<!doctype html>



  


<html class="theme-next muse use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  
    
      
    

    
  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Microsoft YaHei:300,300italic,400,400italic,700,700italic|consolas:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Ajax," />








  <link rel="shortcut icon" type="image/x-icon" href="http://ofy7k3v4s.bkt.clouddn.com/mylogo.png?v=5.0.2" />






<meta name="description" content="&amp;#x670D;&amp;#x52A1;&amp;#x5668;&amp;#x3001;&amp;#x7F51;&amp;#x7EDC;&amp;#x57FA;&amp;#x7840;&amp;#x3001;&amp;#x76F8;&amp;#x5173;&amp;#x77E5;&amp;#x8BC6;&amp;#x4ECB;&amp;#x7ECD;&amp;#x670D;&amp;#x52A1;&amp;#x5668;&amp;#x4ECB;&amp;#x7ECD;&amp;#xFF1A;&amp;#x5E38;&amp;#x89C1;&amp;#x7684;&amp;#x670D;">
<meta property="og:type" content="article">
<meta property="og:title" content="Ajax">
<meta property="og:url" content="https://hongqinma.github.io/2015/01/15/23-Ajax/index.html">
<meta property="og:site_name" content="HongqinMa' Blog">
<meta property="og:description" content="&amp;#x670D;&amp;#x52A1;&amp;#x5668;&amp;#x3001;&amp;#x7F51;&amp;#x7EDC;&amp;#x57FA;&amp;#x7840;&amp;#x3001;&amp;#x76F8;&amp;#x5173;&amp;#x77E5;&amp;#x8BC6;&amp;#x4ECB;&amp;#x7ECD;&amp;#x670D;&amp;#x52A1;&amp;#x5668;&amp;#x4ECB;&amp;#x7ECD;&amp;#xFF1A;&amp;#x5E38;&amp;#x89C1;&amp;#x7684;&amp;#x670D;">
<meta property="og:updated_time" content="2016-12-08T10:06:01.182Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Ajax">
<meta name="twitter:description" content="&amp;#x670D;&amp;#x52A1;&amp;#x5668;&amp;#x3001;&amp;#x7F51;&amp;#x7EDC;&amp;#x57FA;&amp;#x7840;&amp;#x3001;&amp;#x76F8;&amp;#x5173;&amp;#x77E5;&amp;#x8BC6;&amp;#x4ECB;&amp;#x7ECD;&amp;#x670D;&amp;#x52A1;&amp;#x5668;&amp;#x4ECB;&amp;#x7ECD;&amp;#xFF1A;&amp;#x5E38;&amp;#x89C1;&amp;#x7684;&amp;#x670D;">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '6347850919329138000',
      author: 'Hiraku'
    }
  };
</script>




  <link rel="canonical" href="https://hongqinma.github.io/2015/01/15/23-Ajax/"/>


  <title> Ajax | HongqinMa' Blog </title>
</head>

<body itemscope itemtype="//schema.org/WebPage" lang="en">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?10010323";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="//schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta custom-logo">
  
    <div class="site-meta-headline">
      <a>
        <img class="custom-logo-image" src="http://ofy7k3v4s.bkt.clouddn.com/photo.jpg"
             alt="HongqinMa' Blog"/>
      </a>
    </div>
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">HongqinMa' Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">Spell at all costs， to rush you in the future。</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            Tags
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="//schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Ajax
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2015-01-15T20:42:09+08:00" content="2015-01-15">
              2015-01-15
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/JavaScript/" itemprop="url" rel="index">
                    <span itemprop="name">JavaScript</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2015/01/15/23-Ajax/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2015/01/15/23-Ajax/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          

          
              &nbsp; | &nbsp;
              <span class="page-pv"><i class="fa fa-file-o"></i>
              <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
              </span>
          

          
            <span id="busuanzi_container_page_pv">  <span id="busuanzi_value_page_pv"></span> Views</span>
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="&#x670D;&#x52A1;&#x5668;&#x3001;&#x7F51;&#x7EDC;&#x57FA;&#x7840;&#x3001;&#x76F8;&#x5173;&#x77E5;&#x8BC6;&#x4ECB;&#x7ECD;"><a href="#&#x670D;&#x52A1;&#x5668;&#x3001;&#x7F51;&#x7EDC;&#x57FA;&#x7840;&#x3001;&#x76F8;&#x5173;&#x77E5;&#x8BC6;&#x4ECB;&#x7ECD;" class="headerlink" title="&#x670D;&#x52A1;&#x5668;&#x3001;&#x7F51;&#x7EDC;&#x57FA;&#x7840;&#x3001;&#x76F8;&#x5173;&#x77E5;&#x8BC6;&#x4ECB;&#x7ECD;"></a>&#x670D;&#x52A1;&#x5668;&#x3001;&#x7F51;&#x7EDC;&#x57FA;&#x7840;&#x3001;&#x76F8;&#x5173;&#x77E5;&#x8BC6;&#x4ECB;&#x7ECD;</h2><h3 id="&#x670D;&#x52A1;&#x5668;&#x4ECB;&#x7ECD;&#xFF1A;"><a href="#&#x670D;&#x52A1;&#x5668;&#x4ECB;&#x7ECD;&#xFF1A;" class="headerlink" title="&#x670D;&#x52A1;&#x5668;&#x4ECB;&#x7ECD;&#xFF1A;"></a>&#x670D;&#x52A1;&#x5668;&#x4ECB;&#x7ECD;&#xFF1A;</h3><h4 id="&#x5E38;&#x89C1;&#x7684;&#x670D;&#x52A1;&#x5668;&#x8F6F;&#x4EF6;&#x6709;&#xFF1A;"><a href="#&#x5E38;&#x89C1;&#x7684;&#x670D;&#x52A1;&#x5668;&#x8F6F;&#x4EF6;&#x6709;&#xFF1A;" class="headerlink" title="&#x5E38;&#x89C1;&#x7684;&#x670D;&#x52A1;&#x5668;&#x8F6F;&#x4EF6;&#x6709;&#xFF1A;"></a>&#x5E38;&#x89C1;&#x7684;&#x670D;&#x52A1;&#x5668;&#x8F6F;&#x4EF6;&#x6709;&#xFF1A;</h4><ul>
<li>&#x6587;&#x4EF6;&#x670D;&#x52A1;&#x5668;&#xFF1A;Server-U&#x3001;FileZilla&#x3001;VsFTP&#x7B49;&#xFF08;FTP&#x662F;File Transfer Protocol&#x6587;&#x4EF6;&#x4F20;&#x8F93;&#x534F;&#x8BAE;&#xFF09;&#xFF1B;</li>
<li>&#x6570;&#x636E;&#x5E93;&#x670D;&#x52A1;&#x5668;&#xFF1A;oracle&#x3001;mysql&#x3001;SQL server&#x3001;DB2&#x3001;ACCESS&#x7B49;&#xFF1B;</li>
<li>&#x90AE;&#x4EF6;&#x670D;&#x52A1;&#x5668;&#xFF1A;Postfix&#x3001;Sendmail&#x7B49;&#xFF1B;</li>
<li><strong>HTTP&#x670D;&#x52A1;&#x5668;</strong>&#xFF1A;Apache&#x3001;Nginx&#x3001;IIS&#x3001;Tomcat&#x3001;NodeJS&#x7B49;&#xFF1B;</li>
</ul>
<blockquote>
<p>&#x6309;&#x7167;&#x4E0D;&#x540C;&#x7684;&#x5212;&#x5206;&#x6807;&#x51C6;&#xFF0C;&#x670D;&#x52A1;&#x53EF;&#x5212;&#x5206;&#x4E3A;&#x4EE5;&#x4E0B;&#x7C7B;&#x578B;&#xFF1A;</p>
</blockquote>
<p>(1) &#x670D;&#x52A1;&#x5668;&#x7C7B;&#x578B;</p>
<ul>
<li>&#x6309; <em>&#x670D;&#x52A1;&#x7C7B;&#x578B;</em> &#x53EF;&#x5206;&#x4E3A;&#xFF1A;<ul>
<li>&#x6587;&#x4EF6;&#x670D;&#x52A1;&#x5668;</li>
<li>&#x6570;&#x636E;&#x5E93;&#x670D;&#x52A1;&#x5668;</li>
<li>&#x90AE;&#x4EF6;&#x670D;&#x52A1;&#x5668;</li>
<li>Web&#x670D;&#x52A1;&#x5668;&#x7B49;&#xFF1B;</li>
</ul>
</li>
<li>&#x6309; <em>&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;</em> &#x53EF;&#x5206;&#x4E3A;&#xFF1A;<ul>
<li>Linux&#x670D;&#x52A1;&#x5668;</li>
<li>Windows&#x670D;&#x52A1;&#x5668;&#x7B49;&#xFF1B;</li>
</ul>
</li>
<li>&#x6309; <em>&#x5E94;&#x7528;&#x8F6F;&#x4EF6;</em> &#x53EF;&#x5206;&#x4E3A; <ul>
<li>Apache &#x670D;&#x52A1;&#x5668;</li>
<li>Nginx &#x670D;&#x52A1;&#x5668;</li>
<li>IIS &#x670D;&#x52A1;&#x5668;</li>
<li>Tomcat &#x670D;&#x52A1;&#x5668;</li>
<li>weblogic &#x670D;&#x52A1;&#x5668;</li>
<li>WebSphere &#x670D;&#x52A1;&#x5668;</li>
<li>boss &#x670D;&#x52A1;&#x5668;</li>
<li>Node &#x670D;&#x52A1;&#x5668;&#x7B49;</li>
</ul>
</li>
</ul>
<p>(2) HTTP&#x670D;&#x52A1;&#x5668;</p>
<ul>
<li>&#x5373;&#x7F51;&#x7AD9;&#x670D;&#x52A1;&#x5668;&#xFF0C;&#x4E3B;&#x8981;&#x63D0;&#x4F9B;&#x6587;&#x6863;(&#x6587;&#x672C;&#x3001;&#x56FE;&#x7247;&#x3001;&#x89C6;&#x9891;&#x3001;&#x97F3;&#x9891;)&#x6D4F;&#x89C8;&#x670D;&#x52A1;&#xFF0C;&#x4E00;&#x822C;&#x5B89;&#x88C5;Apache&#x3001;Nginx&#x670D;&#x52A1;&#x5668;&#x8F6F;&#x4EF6;&#x3002;</li>
<li>HTTP&#x670D;&#x52A1;&#x5668;&#x53EF;&#x4EE5;&#x7ED3;&#x5408;&#x67D0;&#x4E00;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x5904;&#x7406;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#xFF0C;&#x7531;&#x6B64;&#x8FDB;&#x884C;&#x7684;&#x5F00;&#x53D1;&#xFF0C;&#x901A;&#x5E38;&#x79F0;&#x4E4B;&#x4E3A;<strong>&#x670D;&#x52A1;&#x7AEF;&#x5F00;&#x53D1;</strong>&#x3002; </li>
<li>&#x5E38;&#x89C1;&#x7684;&#x8FD0;&#x884C;&#x5728;&#x670D;&#x52A1;&#x7AEF;&#x7684;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#x5305;&#x62EC; php&#x3001;java&#x3001;.net&#x3001;Python&#x3001;Ruby&#x3001;Perl&#x7B49;&#x3002;</li>
</ul>
<p>(3) &#x5BA2;&#x6237;&#x7AEF;&#x4ECB;&#x7ECD;&#xFF1A;</p>
<ul>
<li>&#x5177;&#x6709;&#x5411;&#x670D;&#x52A1;&#x5668;<strong>&#x7D22;&#x53D6;&#x670D;&#x52A1;</strong>&#x80FD;&#x529B;&#x7684;&#x7EC8;&#x7AEF;&#xFF0C;&#x5982;&#x6BD4;&#x5982; &#x624B;&#x673A;&#x3001;&#x7535;&#x8111;&#x7B49;&#xFF0C;&#x901A;&#x8FC7;&#x5B89;&#x88C5;&#x4E0D;&#x540C;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x8F6F;&#x4EF6;&#xFF0C;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x4E0D;&#x540C;&#x7684;&#x670D;&#x52A1;&#xFF0C;&#x6BD4;&#x5982;&#x901A;&#x8FC7;QQ&#x83B7;&#x5F97;&#x5373;&#x65F6;&#x901A;&#x8BAF;&#x670D;&#x52A1;&#x3001;&#x901A;&#x8FC7;&#x8FC5;&#x96F7;&#x83B7;&#x5F97;&#x4E0B;&#x8F7D;&#x670D;&#x52A1;&#x7B49;&#x3002;</li>
<li>&#x5E38;&#x89C1;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x8F6F;&#x4EF6;&#xFF1A;&#x6D4F;&#x89C8;&#x5668;&#x3001;QQ&#x3001;&#x8FC5;&#x96F7;&#x3001;Foxmail&#x7B49;&#x3002;</li>
<li>&#x4EE5;&#x6D4F;&#x89C8;&#x5668;&#x4E3A;&#x5BBF;&#x4E3B;&#x73AF;&#x5883;&#xFF0C;&#x7ED3;&#x5408; HTML&#x3001;CSS&#x3001;Javascript&#x7B49;&#x6280;&#x672F;&#xFF0C;&#x800C;&#x8FDB;&#x884C;&#x7684;&#x4E00;&#x7CFB;&#x5217;&#x5F00;&#x53D1;&#xFF0C;&#x901A;&#x5E38;&#x79F0;&#x4E4B;&#x4E3A;<strong>&#x524D;&#x7AEF;&#x5F00;&#x53D1;</strong>&#x3002;</li>
</ul>
<h2 id="&#x7F51;&#x7EDC;&#x57FA;&#x7840;&#xFF1A;"><a href="#&#x7F51;&#x7EDC;&#x57FA;&#x7840;&#xFF1A;" class="headerlink" title="&#x7F51;&#x7EDC;&#x57FA;&#x7840;&#xFF1A;"></a>&#x7F51;&#x7EDC;&#x57FA;&#x7840;&#xFF1A;</h2><h3 id="IP&#x5730;&#x5740;"><a href="#IP&#x5730;&#x5740;" class="headerlink" title="IP&#x5730;&#x5740;"></a>IP&#x5730;&#x5740;</h3><ul>
<li>&#x6240;&#x8C13;IP&#x5730;&#x5740;&#x5C31;&#x662F;&#x7ED9;&#x6BCF;&#x4E2A;&#x8FDE;&#x63A5;&#x5728;&#x4E92;&#x8054;&#x7F51;&#x4E0A;&#x7684;&#x4E3B;&#x673A;&#x5206;&#x914D;&#x7684;&#x4E00;&#x4E2A;32&#x4F4D;&#x5730;&#x5740;&#x3002;(&#x5C31;&#x50CF;&#x6BCF;&#x90E8;&#x624B;&#x673A;&#x80FD;&#x6B63;&#x5E38;&#x901A;&#x8BDD;&#x9700;&#x8981;&#x4E00;&#x4E2A;&#x53F7;&#x7801;&#x4E00;&#x6837;)</li>
<li>&#x67E5;&#x770B;&#x672C;&#x673A;IP&#x5730;&#x5740; ping&#x3001;ipconfig&#x3001;ifconfig&#xFF08;linux&#xFF09;</li>
</ul>
<h3 id="&#x57DF;&#x540D;"><a href="#&#x57DF;&#x540D;" class="headerlink" title="&#x57DF;&#x540D;"></a>&#x57DF;&#x540D;</h3><ul>
<li>&#x7531;&#x4E8E;IP&#x5730;&#x5740;&#x57FA;&#x4E8E;&#x6570;&#x5B57;&#xFF0C;&#x4E0D;&#x65B9;&#x4FBF;&#x8BB0;&#x5FC6;&#xFF0C;&#x4E8E;&#x662F;&#x4FBF;&#x7528;&#x57DF;&#x540D;&#x6765;&#x4EE3;&#x66FF;IP&#x5730;&#x5740;&#xFF0C;&#x57DF;&#x540D;&#x662F;&#x4E00;&#x4E2A;IP&#x5730;&#x5740;&#x7684;&#x201C;&#x9762;&#x5177;&#x201D;  </li>
<li>&#x67E5;&#x770B;&#x57DF;&#x540D;&#x5BF9;&#x5E94;&#x7684;IP&#x5730;&#x5740; ping</li>
</ul>
<h3 id="DNS&#x670D;&#x52A1;"><a href="#DNS&#x670D;&#x52A1;" class="headerlink" title="DNS&#x670D;&#x52A1;"></a>DNS&#x670D;&#x52A1;</h3><ul>
<li>DNS&#xFF08;Domain Name System&#xFF09;&#x56E0;&#x7279;&#x7F51;&#x4E0A;&#x4F5C;&#x4E3A;&#x57DF;&#x540D;&#x548C;IP&#x5730;&#x5740;&#x76F8;&#x4E92;&#x6620;&#x5C04;&#x7684;&#x4E00;&#x4E2A;&#x5206;&#x5E03;&#x5F0F;&#x6570;&#x636E;&#x5E93;&#xFF0C;&#x80FD;&#x591F;&#x4F7F;&#x7528;&#x6237;&#x66F4;&#x65B9;&#x4FBF;&#x7684;&#x8BBF;&#x95EE;&#x4E92;&#x8054;&#x7F51;&#xFF0C;&#x800C;&#x4E0D;&#x7528;&#x53BB;&#x8BB0;&#x4F4F;&#x80FD;&#x591F;&#x88AB;&#x673A;&#x5668;&#x76F4;&#x63A5;&#x8BFB;&#x53D6;&#x7684;IP&#x6570;&#x4E32;&#x3002;</li>
<li>&#x7B80;&#x5355;&#x7684;&#x8BF4;&#x5C31;&#x662F;&#x8BB0;&#x5F55;IP&#x5730;&#x5740;&#x548C;&#x57DF;&#x540D;&#x4E4B;&#x95F4;&#x5BF9;&#x5E94;&#x5173;&#x7CFB;&#x7684;&#x670D;&#x52A1;&#x3002;</li>
<li>&#x67E5;&#x627E;&#x4F18;&#x5148;&#x7EA7; &#x672C;&#x673A; hosts &#x6587;&#x4EF6;&#x3001;DNS&#x670D;&#x52A1;&#x5668;</li>
<li>ipconfig /flushdns &#x5237;&#x65B0;DNS</li>
</ul>
<h3 id="&#x7AEF;&#x53E3;"><a href="#&#x7AEF;&#x53E3;" class="headerlink" title="&#x7AEF;&#x53E3;"></a>&#x7AEF;&#x53E3;</h3><ul>
<li>&#x7AEF;&#x53E3;&#x53F7;&#x662F;&#x8BA1;&#x7B97;&#x673A;&#x4E0E;&#x5916;&#x754C;&#x901A;&#x8BAF;&#x4EA4;&#x6D41;&#x7684;&#x51FA;&#x53E3;&#xFF0C;&#x6BCF;&#x4E2A;&#x7AEF;&#x53E3;&#x5BF9;&#x5E94;&#x4E0D;&#x540C;&#x7684;&#x670D;&#x52A1;&#x3002;<em>&#x73B0;&#x5B9E;&#x751F;&#x6D3B;&#x4E2D;&#xFF0C;&#x94F6;&#x884C;&#x4E0D;&#x540C;&#x7684;&#x7A97;&#x53E3;&#x529E;&#x7406;&#x4E0D;&#x540C;&#x7684;&#x4E1A;&#x52A1;&#x3002;</em></li>
<li>&#x67E5;&#x770B;&#x7AEF;&#x53E3;&#x5360;&#x7528;&#x60C5;&#x51B5; <code>netstat -an</code></li>
<li>&#x5E38;&#x89C1;&#x7AEF;&#x53E3;&#x53F7; 80&#x3001;8080&#x3001;3306&#x3001;21&#x3001;22</li>
</ul>
<h2 id="&#x8F6F;&#x4EF6;&#x67B6;&#x6784;"><a href="#&#x8F6F;&#x4EF6;&#x67B6;&#x6784;" class="headerlink" title="&#x8F6F;&#x4EF6;&#x67B6;&#x6784;"></a>&#x8F6F;&#x4EF6;&#x67B6;&#x6784;</h2><h3 id="C-S&#x7ED3;&#x6784;"><a href="#C-S&#x7ED3;&#x6784;" class="headerlink" title="C/S&#x7ED3;&#x6784;"></a>C/S&#x7ED3;&#x6784;</h3><blockquote>
<p>&#x5373;<strong>C</strong>lient&#x3001;<strong>S</strong>erver</p>
</blockquote>
<ul>
<li>&#x5728;C/S&#x7ED3;&#x6784;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4E0D;&#x540C;&#x7684;&#x670D;&#x52A1;&#x9700;&#x8981;&#x5B89;&#x88C5;&#x4E0D;&#x540C;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x8F6F;&#x4EF6;&#xFF0C;</li>
<li>&#x6BD4;&#x5982;QQ&#x3001;&#x8FC5;&#x96F7;&#x3001;Foxmail &#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0B;&#x5B89;&#x88C5;&#x7684;&#x8F6F;&#x4EF6;&#x4F1A;&#x8D8A;&#x6765;&#x8D8A;&#x591A;&#xFF0C;&#x540C;&#x65F6;&#x4E5F;&#x6709;&#x8BB8;&#x591A;&#x5F0A;&#x7AEF;&#xFF0C;&#x6BD4;&#x5982;A&#x51FA;&#x5DEE;&#xFF0C;&#x9700;&#x8981;&#x5728;B&#x7535;&#x8111;&#x4E0A;&#x67E5;&#x6536;&#x90AE;&#x4EF6;&#xFF0C;&#x4F46;&#x662F;B&#x7535;&#x8111;&#x5E76;&#x672A;&#x5B89;&#x88C5;Foxmail&#x7B49;&#x7C7B;&#x4F3C;&#x7684;&#x5BA2;&#x6237;&#x7AEF;&#x8F6F;&#x4EF6;&#xFF0C;&#x8FD9;&#x6837;&#x4E0D;&#x5F97;&#x4E0D;&#x5148;&#x53BB;&#x4E0B;&#x8F7D;Foxmail&#xFF0C;&#x975E;&#x5E38;&#x4E0D;&#x65B9;&#x4FBF;&#x3002;</li>
</ul>
<h3 id="B-S&#x7ED3;&#x6784;"><a href="#B-S&#x7ED3;&#x6784;" class="headerlink" title="B/S&#x7ED3;&#x6784;"></a>B/S&#x7ED3;&#x6784;</h3><blockquote>
<p>&#x5373;<strong>B</strong>roswer&#x3001;<strong>S</strong>erver</p>
</blockquote>
<ul>
<li>&#x89E3;&#x51B3;&#x4E86;C/S&#x6240;&#x5E26;&#x6765;&#x7684;&#x4E0D;&#x4FBF;</li>
<li>&#x5C06;&#x6240;&#x6709;&#x7684;&#x670D;&#x52A1;&#x90FD;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6D4F;&#x89C8;&#x5668;&#x6765;&#x5B8C;&#x6210;&#xFF08;&#x56E0;&#x4E3A;&#x57FA;&#x672C;&#x6240;&#x6709;&#x6D4F;&#x89C8;&#x5668;&#x90FD;&#x5B89;&#x88C5;&#x4E86;&#x6D4F;&#x89C8;&#x5668;&#xFF09;&#xFF0C;&#x4F46;B/S&#x4E5F;&#x6709;&#x4E00;&#x4E9B;&#x4E0D;&#x5229;&#xFF0C;&#x6BD4;&#x5982;&#x64CD;&#x4F5C;&#x7A33;&#x5B9A;&#x6027;&#x3001;&#x6D41;&#x7545;&#x5EA6;&#x7B49;&#x65B9;&#x9762;&#x76F8;&#x5BF9;&#x8F83;&#x5F31;&#x3002;</li>
</ul>
<h2 id="&#x7F51;&#x7EDC;&#x4F20;&#x8F93;&#x534F;&#x8BAE;"><a href="#&#x7F51;&#x7EDC;&#x4F20;&#x8F93;&#x534F;&#x8BAE;" class="headerlink" title="&#x7F51;&#x7EDC;&#x4F20;&#x8F93;&#x534F;&#x8BAE;"></a>&#x7F51;&#x7EDC;&#x4F20;&#x8F93;&#x534F;&#x8BAE;</h2><h3 id="&#x5E38;&#x89C1;&#x534F;&#x8BAE;"><a href="#&#x5E38;&#x89C1;&#x534F;&#x8BAE;" class="headerlink" title="&#x5E38;&#x89C1;&#x534F;&#x8BAE;"></a>&#x5E38;&#x89C1;&#x534F;&#x8BAE;</h3><ul>
<li>HTTP&#x3001;HTTPS &#x8D85;&#x6587;&#x672C;&#x4F20;&#x8F93;&#x534F;&#x8BAE; </li>
<li>FTP &#x6587;&#x4EF6;&#x4F20;&#x8F93;&#x534F;&#x8BAE;</li>
<li>SMTP &#x7B80;&#x5355;&#x90AE;&#x4EF6;&#x4F20;&#x8F93;&#x534F;&#x8BAE;</li>
</ul>
<h3 id="http&#x534F;&#x8BAE;"><a href="#http&#x534F;&#x8BAE;" class="headerlink" title="http&#x534F;&#x8BAE;"></a>http&#x534F;&#x8BAE;</h3><ul>
<li>&#x8D85;&#x6587;&#x672C;&#x4F20;&#x8F93;&#x534F;&#x8BAE;&#xFF08;HTTP&#xFF0C;HyperText Transfer Protocol) &#x7F51;&#x7AD9;&#x662F;&#x57FA;&#x4E8E;HTTP&#x534F;&#x8BAE;&#x7684;&#xFF0C;&#x4F8B;&#x5982;&#x7F51;&#x7AD9;&#x7684;&#x56FE;&#x7247;&#x3001;CSS&#x3001;JS&#x7B49;&#x90FD;&#x662F;&#x57FA;&#x4E8E;HTTP&#x534F;&#x8BAE;&#x8FDB;&#x884C;&#x4F20;&#x8F93;&#x7684;&#x3002;</li>
<li>HTML Hypertext Markup Language</li>
<li>HTTP&#x534F;&#x8BAE;&#x662F;&#x7531;&#x4ECE;&#x5BA2;&#x6237;&#x673A;&#x5230;&#x670D;&#x52A1;&#x5668;&#x7684;&#x8BF7;&#x6C42;(Request)&#x548C;&#x4ECE;&#x670D;&#x52A1;&#x5668;&#x5230;&#x5BA2;&#x6237;&#x673A;&#x7684;&#x54CD;&#x5E94;(Response)&#x8FDB;&#x884C;&#x4E86;&#x7EA6;&#x675F;&#x548C;&#x89C4;&#x8303;&#x3002;&#x5373;HTTP&#x534F;&#x8BAE;&#x4E3B;&#x8981;&#x7531;&#x8BF7;&#x6C42;&#x548C;&#x54CD;&#x5E94;&#x6784;&#x6210;&#x3002;</li>
</ul>
<blockquote>
<p>&#x5E38;&#x7528;&#x8BF7;&#x6C42;&#x65B9;&#x6CD5; <strong>POST</strong>&#x3001;<strong>GET</strong>&#x3001;PUT&#x3001;DELETE</p>
</blockquote>
<h4 id="&#x8BF7;&#x6C42;&#x7531;-4-&#x90E8;&#x5206;&#x7EC4;&#x6210;"><a href="#&#x8BF7;&#x6C42;&#x7531;-4-&#x90E8;&#x5206;&#x7EC4;&#x6210;" class="headerlink" title="&#x8BF7;&#x6C42;&#x7531; 4 &#x90E8;&#x5206;&#x7EC4;&#x6210;"></a>&#x8BF7;&#x6C42;&#x7531; 4 &#x90E8;&#x5206;&#x7EC4;&#x6210;</h4><ul>
<li>HTTP &#x8BF7;&#x6C42;&#x65B9;&#x6CD5;&#x6216; &#x201C;&#x52A8;&#x4F5C;&#x201D;</li>
<li>&#x6B63;&#x5728;&#x8BF7;&#x6C42;&#x7684; URL </li>
<li>&#x4E00;&#x4E2A;&#x53EF;&#x9009;&#x7684;&#x8BF7;&#x6C42;&#x5934;&#x96C6;&#x5408;&#x3002;&#x5176;&#x4E2D;&#x53EF;&#x80FD;&#x5305;&#x62EC;&#x8EAB;&#x4EFD;&#x9A8C;&#x8BC1;&#x4FE1;&#x606F;</li>
<li>&#x4E00;&#x4E2A;&#x53EF;&#x9009;&#x7684;&#x8BF7;&#x6C42;&#x4F53;</li>
</ul>
<p><strong>&#x8BF7;&#x6C42;&#x5934;</strong></p>
<p>&#x7531;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#x3001;&#x8BF7;&#x6C42;URL&#x548C;&#x534F;&#x8BAE;&#x7248;&#x672C;&#x6784;&#x6210;</p>
<ul>
<li><code>GET /day01/code/login.php?username=123&amp;password=123 HTTP/1.1</code></li>
<li><code>POST /day01/code/login.php HTTP/1.1</code></li>
</ul>
<p><strong>&#x8BF7;&#x6C42;&#x884C;</strong></p>
<ul>
<li><code>Host&#xFF1A;localhost</code><ul>
<li>&#x8BF7;&#x6C42;&#x7684;&#x4E3B;&#x673A;&#xFF0C;&#x53D1;&#x51FA;&#x8BF7;&#x6C42;&#x7684;&#x9875;&#x9762;&#x6240;&#x5728;&#x7684;&#x57DF;</li>
</ul>
</li>
<li><code>Cache-Control&#xFF1A;max-age=0</code><ul>
<li>&#x63A7;&#x5236;&#x7F13;&#x5B58;</li>
</ul>
</li>
<li><code>Accept</code><ul>
<li><em>/</em> &#x63A5;&#x53D7;&#x7684;&#x6587;&#x6863;MIME&#x7C7B;&#x578B;</li>
</ul>
</li>
<li><code>User-Agent</code><ul>
<li>&#x5F88;&#x91CD;&#x8981;&#xFF0C;&#x6D4F;&#x89C8;&#x5668;&#x7684;&#x7528;&#x6237;&#x4EE3;&#x7406;&#x5B57;&#x7B26;&#x4E32;</li>
</ul>
</li>
<li><code>Referer</code><ul>
<li>&#x4ECE;&#x54EA;&#x4E2A;URL&#x8DF3;&#x8F6C;&#x8FC7;&#x6765;&#x7684;&#xFF0C;&#x53D1;&#x51FA;&#x8BF7;&#x6C42;&#x7684;&#x9875;&#x9762; URL</li>
</ul>
</li>
<li><code>Accept-Encoding</code><ul>
<li>&#x53EF;&#x63A5;&#x53D7;&#x7684;&#x538B;&#x7F29;&#x683C;&#x5F0F;</li>
</ul>
</li>
<li><code>If-None-Match</code><ul>
<li>&#x8BB0;&#x5F55;&#x670D;&#x52A1;&#x5668;&#x54CD;&#x5E94;&#x7684;ETag&#x503C;&#xFF0C;&#x7528;&#x4E8E;&#x63A7;&#x5236;&#x7F13;&#x5B58;,&#x6B64;&#x503C;&#x662F;&#x7531;&#x670D;&#x52A1;&#x5668;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x7684;</li>
</ul>
</li>
<li><code>If-Modified-Since</code><ul>
<li>&#x8BB0;&#x5F55;&#x670D;&#x52A1;&#x5668;&#x54CD;&#x5E94;&#x7684;Last-Modified&#x503C;,&#x6B64;&#x503C;&#x662F;&#x7531;&#x670D;&#x52A1;&#x5668;&#x81EA;&#x52A8;&#x751F;&#x6210;&#x7684;</li>
</ul>
</li>
<li><code>Accept-Charset</code><ul>
<li>&#x6D4F;&#x89C8;&#x5668;&#x80FD;&#x591F;&#x663E;&#x793A;&#x7684;&#x5B57;&#x7B26;&#x96C6;</li>
</ul>
</li>
<li><code>Accept-Language</code><ul>
<li>&#x6D4F;&#x89C8;&#x5668;&#x5F53;&#x524D;&#x8BBE;&#x7F6E;&#x7684;&#x8BED;&#x8A00;</li>
</ul>
</li>
<li><code>Connection</code><ul>
<li>&#x6D4F;&#x89C8;&#x5668;&#x548C;&#x670D;&#x52A1;&#x5668;&#x4E4B;&#x95F4;&#x8FDE;&#x63A5;&#x7684;&#x7C7B;&#x578B;</li>
</ul>
</li>
<li><code>Cookie</code><ul>
<li>&#x5F53;&#x524D;&#x9875;&#x9762;&#x8BBE;&#x7F6E;&#x7684;&#x4EFB;&#x4F55; Cookie</li>
</ul>
</li>
</ul>
<p><strong>&#x8BF7;&#x6C42;&#x4E3B;&#x4F53;</strong></p>
<ul>
<li>&#x5373;&#x4F20;&#x9012;&#x7ED9;&#x670D;&#x52A1;&#x7AEF;&#x7684;&#x6570;&#x636E;</li>
<li>&#x6CE8;&#xFF1A;&#x5F53;&#x4EE5;post&#x5F62;&#x5F0F;&#x63D0;&#x4EA4;&#x8868;&#x5355;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8BF7;&#x6C42;&#x5934;&#x91CC;&#x4F1A;&#x8BBE;&#x7F6E;</li>
<li><code>Content-Type: application/x-www-form-urlencoded</code>&#xFF0C;&#x4EE5;get&#x5F62;&#x5F0F;&#x5F53;&#x4E0D;&#x9700;&#x8981;</li>
</ul>
<h3 id="&#x54CD;&#x5E94;&#x548C;&#x54CD;&#x5E94;&#x62A5;&#x6587;"><a href="#&#x54CD;&#x5E94;&#x548C;&#x54CD;&#x5E94;&#x62A5;&#x6587;" class="headerlink" title="&#x54CD;&#x5E94;&#x548C;&#x54CD;&#x5E94;&#x62A5;&#x6587;"></a>&#x54CD;&#x5E94;&#x548C;&#x54CD;&#x5E94;&#x62A5;&#x6587;</h3><p>&#x54CD;&#x5E94;&#x7531;&#x670D;&#x52A1;&#x5668;&#x53D1;&#x51FA;&#xFF0C;&#x5176;&#x89C4;&#x8303;&#x683C;&#x5F0F;&#x4E3A;&#xFF1A;&#x72B6;&#x6001;&#x884C;&#x3001;&#x54CD;&#x5E94;&#x5934;&#x3001;&#x54CD;&#x5E94;&#x4E3B;&#x4F53;&#x3002;</p>
<blockquote>
<p>&#x670D;&#x52A1;&#x5668;&#x8FD4;&#x56DE;&#x7684; HTTP &#x54CD;&#x5E94;&#x5305;&#x542B; 3 &#x90E8;&#x5206;</p>
</blockquote>
<ul>
<li>&#x4E00;&#x4E2A;&#x6570;&#x5B57;&#x548C;&#x6587;&#x5B57;&#x7EC4;&#x6210;&#x7684;&#x72B6;&#x6001;&#x7801;&#xFF0C;&#x7528;&#x6765;&#x663E;&#x793A;&#x8BF7;&#x6C42;&#x7684;&#x6210;&#x529F;&#x548C;&#x5931;&#x8D25;</li>
<li>&#x4E00;&#x4E2A;&#x54CD;&#x5E94;&#x5934;&#x96C6;&#x5408;</li>
<li>&#x54CD;&#x5E94;&#x4E3B;&#x4F53;</li>
</ul>
<p><strong>&#x72B6;&#x6001;&#x884C;</strong></p>
<p>&#x7531;&#x534F;&#x8BAE;&#x7248;&#x672C;&#x53F7;&#x3001;&#x72B6;&#x6001;&#x7801;&#x548C;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x6784;&#x6210; <code>HTTP/1.1 200 OK</code></p>
<p><strong>&#x54CD;&#x5E94;&#x5934;</strong></p>
<ul>
<li><code>Date</code> &#xFF1A;<ul>
<li>&#x54CD;&#x5E94;&#x65F6;&#x95F4;</li>
</ul>
</li>
<li><code>Server</code> &#xFF1A;<ul>
<li>&#x670D;&#x52A1;&#x5668;&#x4FE1;&#x606F;</li>
</ul>
</li>
<li><code>Last-Modified</code> &#xFF1A;<ul>
<li>&#x8D44;&#x6E90;&#x6700;&#x540E;&#x4FEE;&#x6539;&#x65F6;&#x95F4; &#x7531;&#x670D;&#x52A1;&#x5668;&#x81EA;&#x52A8;&#x751F;&#x6210;</li>
</ul>
</li>
<li><code>ETag</code> &#xFF1A;<ul>
<li>&#x8D44;&#x6E90;&#x4FEE;&#x6539;&#x540E;&#x751F;&#x6210;&#x7684;&#x552F;&#x4E00;&#x6807;&#x8BC6; &#x7531;&#x670D;&#x52A1;&#x5668;&#x81EA;&#x52A8;&#x751F;&#x6210;</li>
</ul>
</li>
<li><code>Content-Length</code> &#xFF1A;<ul>
<li>&#x54CD;&#x5E94;&#x4E3B;&#x4F53;&#x957F;&#x5EA6;</li>
</ul>
</li>
<li><code>Content-Type</code> &#xFF1A;<ul>
<li>&#x54CD;&#x5E94;&#x8D44;&#x6E90;&#x7684;&#x7C7B;&#x578B;</li>
</ul>
</li>
</ul>
<p><strong>&#x54CD;&#x5E94;&#x4E3B;&#x4F53;</strong></p>
<p>&#x5373;&#x670D;&#x52A1;&#x7AEF;&#x8FD4;&#x56DE;&#x7ED9;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x5185;&#x5BB9;&#xFF1B;</p>
<p>&#x72B6;&#x6001;&#x7801;&#xFF0C;&#x5E38;&#x89C1;&#x7684;&#x6709;: </p>
<ul>
<li>200&#x4EE3;&#x8868;&#x6210;&#x529F;</li>
<li>304&#x6587;&#x6863;&#x672A;&#x4FEE;&#x6539;</li>
<li>403&#x6CA1;&#x6709;&#x6743;&#x9650;</li>
<li>404&#x672A;&#x627E;&#x5230;</li>
<li>500&#x670D;&#x52A1;&#x5668;&#x9519;&#x8BEF;</li>
</ul>
<h2 id="JavaScript-&#x539F;&#x751F;&#x7684;-Ajax"><a href="#JavaScript-&#x539F;&#x751F;&#x7684;-Ajax" class="headerlink" title="JavaScript &#x539F;&#x751F;&#x7684; Ajax"></a>JavaScript &#x539F;&#x751F;&#x7684; Ajax</h2><p>Ajax &#x7684;&#x6280;&#x672F;&#x6838;&#x5FC3;&#x662F; <code>XMLHttpRequest</code> &#x5BF9;&#x8C61;&#x3002;<em>AJAX &#x4E0D;&#x662F;&#x4E00;&#x95E8;&#x7684;&#x65B0;&#x7684;&#x8BED;&#x8A00;&#xFF0C;&#x800C;&#x662F;&#x5BF9;&#x73B0;&#x6709;&#x6280;&#x672F;&#x7684;&#x7EFC;&#x5408;&#x5229;&#x7528;&#x3002;&#x672C;&#x8D28;&#x662F;&#x5728;HTTP&#x534F;&#x8BAE;&#x7684;&#x57FA;&#x7840;&#x4E0A;&#x4EE5;&#x5F02;&#x6B65;&#x7684;&#x65B9;&#x5F0F;&#x4E0E;&#x670D;&#x52A1;&#x5668;&#x8FDB;&#x884C;&#x901A;&#x4FE1;&#x3002;</em></p>
<h3 id="&#x5F02;&#x6B65;"><a href="#&#x5F02;&#x6B65;" class="headerlink" title="&#x5F02;&#x6B65;"></a>&#x5F02;&#x6B65;</h3><blockquote>
<p>&#x6307;&#x67D0;&#x6BB5;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x65F6;&#x4E0D;&#x4F1A;&#x963B;&#x585E;&#x5176;&#x5B83;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#xFF0C;&#x5176;&#x8868;&#x73B0;&#x5F62;&#x5F0F;&#x4E3A;&#x7A0B;&#x5E8F;&#x7684;&#x6267;&#x884C;&#x987A;&#x5E8F;&#x4E0D;&#x4F9D;&#x8D56;&#x7A0B;&#x5E8F;&#x672C;&#x8EAB;&#x7684;&#x4E66;&#x5199;&#x987A;&#x5E8F;&#xFF0C;&#x76F8;&#x53CD;&#x5219;&#x4E3A;&#x540C;&#x6B65;&#x3002;</p>
</blockquote>
<p><strong>&#x5176;&#x4F18;&#x52BF;&#x5728;&#x4E8E;&#x4E0D;&#x963B;&#x585E;&#x7A0B;&#x5E8F;&#x7684;&#x6267;&#x884C;&#xFF0C;&#x4ECE;&#x800C;&#x63D0;&#x5347;&#x6574;&#x4F53;&#x6267;&#x884C;&#x6548;&#x7387;&#x3002;</strong></p>
<h3 id="XMLHttpRequest-&#x5BF9;&#x8C61;"><a href="#XMLHttpRequest-&#x5BF9;&#x8C61;" class="headerlink" title="XMLHttpRequest &#x5BF9;&#x8C61;"></a>XMLHttpRequest &#x5BF9;&#x8C61;</h3><p>&#x6D4F;&#x89C8;&#x5668;&#x5185;&#x5EFA;&#x5BF9;&#x8C61;&#xFF0C;&#x7528;&#x4E8E;&#x5728;&#x540E;&#x53F0;&#x4E0E;&#x670D;&#x52A1;&#x5668;&#x901A;&#x4FE1;(&#x4EA4;&#x6362;&#x6570;&#x636E;) &#xFF0C;&#x7531;&#x6B64;&#x6211;&#x4EEC;&#x4FBF;&#x53EF;&#x5B9E;&#x73B0;&#x5BF9;&#x7F51;&#x9875;&#x7684;&#x90E8;&#x5206;&#x66F4;&#x65B0;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x5237;&#x65B0;&#x6574;&#x4E2A;&#x9875;&#x9762;&#x3002;</p>
<blockquote>
<p>HTTP&#x8BF7;&#x6C42;3&#x4E2A;&#x7EC4;&#x6210;&#x90E8;&#x5206;&#x4E0E;XMLHttpRequest&#x65B9;&#x6CD5;&#x7684;&#x5BF9;&#x5E94;&#x5173;&#x7CFB;</p>
</blockquote>
<ul>
<li>&#x8BF7;&#x6C42;&#x884C; xhr.open(&#x2018;post&#x2019;,&#x2019;01.php&#x2019;);</li>
<li>&#x8BF7;&#x6C42;&#x5934; xhr.setRequestHeader(&#x2018;Content-Type&#x2019;,&#x2019;application/x-www-form-urlencoded&#x2019;); get&#x8BF7;&#x6C42;&#x53EF;&#x4EE5;&#x4E0D;&#x8BBE;&#x7F6E;</li>
<li>&#x8BF7;&#x6C42;&#x4E3B;&#x4F53; xhr.send(&#x201C;name=xjj&amp;age=10&#x201D;); get &#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#x53EF;&#x4EE5;&#x4F20;&#x7A7A; </li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// &#x9002;&#x7528;&#x4E8E; IE7 &#x4E4B;&#x524D;&#x7684;&#x7248;&#x672C;</span></div><div class="line">  <span class="function"><span class="keyword">function</span> <span class="title">createXHR</span>(<span class="params"></span>) </span>{</div><div class="line">    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="built_in">arguments</span>.callee.activeXString != <span class="string">&quot;string&quot;</span>) {</div><div class="line">      <span class="keyword">var</span> versions = [</div><div class="line">        <span class="string">&quot;MSXML2.XMLHttp.6.0&quot;</span>,</div><div class="line">        <span class="string">&quot;MSXML2.XMLHttp.3.0&quot;</span>,</div><div class="line">        <span class="string">&quot;MSXML2.XMLHtt&quot;</span></div><div class="line">      ], i, len;</div><div class="line">      <span class="keyword">for</span> (i = <span class="number">0</span>, len = versions.length; i &lt; len; i++) {</div><div class="line">        <span class="keyword">try</span> {</div><div class="line">          <span class="keyword">new</span> ActiveXObject(versions[i]);</div><div class="line">          <span class="built_in">arguments</span>.callee.activeXString = versions[i];</div><div class="line">          <span class="keyword">break</span>;</div><div class="line">        } <span class="keyword">catch</span> (ex) {</div><div class="line">          <span class="comment">// &#x8DF3;&#x8FC7;</span></div><div class="line">        }</div><div class="line">      }</div><div class="line">    }</div><div class="line">    <span class="keyword">return</span> <span class="keyword">new</span> ActiveXObject(<span class="built_in">arguments</span>.callee.activeXString);</div><div class="line">  }</div></pre></td></tr></table></figure>
<p>IE7+&#x3001;FireFox&#x3001;Opera&#x3001;Chrome&#x3001;Safari &#x90FD;&#x652F;&#x6301;&#x539F;&#x751F;&#x7684; XHR &#x5BF9;&#x8C61;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> xhr = <span class="keyword">new</span> XMLHttpRequest();</div></pre></td></tr></table></figure>
<p>&#x5C01;&#x88C5;&#x83B7;&#x53D6; xhr &#x5BF9;&#x8C61;&#x7684;&#x51FD;&#x6570;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">createXHR</span>(<span class="params"></span>) </span>{</div><div class="line">  <span class="keyword">if</span> (<span class="keyword">typeof</span> XMLHttpRequest != <span class="string">&quot;undefined&quot;</span>) {</div><div class="line">    <span class="keyword">return</span> <span class="keyword">new</span> XMLHttpRequest();</div><div class="line">  } <span class="keyword">else</span> <span class="keyword">if</span> (<span class="keyword">typeof</span> ActiveXObject != <span class="string">&quot;undefined&quot;</span>) {</div><div class="line">    <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="built_in">arguments</span>.callee.activeXString != <span class="string">&quot;string&quot;</span>) {</div><div class="line">      <span class="keyword">var</span> versions = [</div><div class="line">        <span class="string">&quot;MSXML2.XMLHttp.6.0&quot;</span>,</div><div class="line">        <span class="string">&quot;MSXML2.XMLHttp.3.0&quot;</span>,</div><div class="line">        <span class="string">&quot;MSXML2.XMLHtt&quot;</span></div><div class="line">      ], i, len;</div><div class="line">      <span class="keyword">for</span> (i = <span class="number">0</span>, len = versions.length; i &lt; len; i++) {</div><div class="line">        <span class="keyword">try</span> {</div><div class="line">          <span class="keyword">new</span> ActiveXObject(versions[i]);</div><div class="line">          <span class="built_in">arguments</span>.callee.activeXString = versions[i];</div><div class="line">          <span class="keyword">break</span>;</div><div class="line">        } <span class="keyword">catch</span> (ex) {</div><div class="line">          <span class="comment">// &#x8DF3;&#x8FC7;</span></div><div class="line">        }</div><div class="line">      }</div><div class="line">    }</div><div class="line">    <span class="keyword">return</span> <span class="keyword">new</span> ActiveXObject(<span class="built_in">arguments</span>.callee.activeXString);</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      <span class="keyword">throw</span> <span class="keyword">new</span> <span class="built_in">Error</span> (<span class="string">&quot;No XHR object is available&quot;</span>);</div><div class="line">    }</div><div class="line">}</div></pre></td></tr></table></figure>
<h3 id="XMLHttpRequest-&#x5BF9;&#x8C61;&#x4F7F;&#x7528;"><a href="#XMLHttpRequest-&#x5BF9;&#x8C61;&#x4F7F;&#x7528;" class="headerlink" title="XMLHttpRequest &#x5BF9;&#x8C61;&#x4F7F;&#x7528;"></a>XMLHttpRequest &#x5BF9;&#x8C61;&#x4F7F;&#x7528;</h3><ul>
<li>open() &#x65B9;&#x6CD5;<ul>
<li>&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;<ul>
<li>&#x8981;&#x53D1;&#x9001;&#x7684;&#x8BF7;&#x6C42;&#x7684;&#x7C7B;&#x578B;&#xFF1A;(&#x201C;get&#x201D;, &#x201C;post&#x201D;) </li>
<li>&#x8BF7;&#x6C42;&#x7684; URL &#xFF0C;&#x662F;&#x76F8;&#x5BF9;&#x4E8E;&#x6267;&#x884C;&#x4EE3;&#x7801;&#x7684;&#x5F53;&#x524D;&#x9875;&#x9762;&#xFF08;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#xFF09;</li>
<li>&#x8868;&#x793A;&#x662F;&#x5426;&#x5F02;&#x6B65;&#x53D1;&#x9001;&#x8BF7;&#x6C42;&#x7684;&#x5E03;&#x5C14;&#x503C;</li>
</ul>
</li>
<li>&#x53EA;&#x80FD;&#x60F3;&#x7528;&#x4E00;&#x4E2A;&#x57DF;&#x4E2D;&#x4F7F;&#x7528;&#x76F8;&#x540C;&#x7AEF;&#x53E3;&#x548C;&#x534F;&#x8BAE;&#x7684; URL &#x53D1;&#x9001;&#x8BF7;&#x6C42;&#x3002;&#x5982;&#x679C; URL &#x4E0E;&#x542F;&#x52A8;&#x8BF7;&#x6C42;&#x7684;&#x9875;&#x9762;&#x6709;&#x4EFB;&#x4F55;&#x5DEE;&#x522B;&#xFF0C;&#x90FD;&#x4F1A;&#x53D1;&#x751F;&#x5B89;&#x5168;&#x9519;&#x8BEF;&#x3002;</li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">xhr.open(<span class="string">&quot;get&quot;</span>, <span class="string">&quot;exam.php&quot;</span>, <span class="literal">false</span>);</div><div class="line">xhr.send(<span class="literal">null</span>);</div></pre></td></tr></table></figure>
<ul>
<li>send() &#x65B9;&#x6CD5;<ul>
<li>&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x8BF7;&#x6C42;&#x4E3B;&#x9898;&#x53D1;&#x9001;&#x7684;&#x6570;&#x636E;</li>
<li>&#x5982;&#x679C;&#x4E0D;&#x9700;&#x8981;&#x8BF7;&#x6C42;&#x4E3B;&#x4F53;&#x53D1;&#x9001;&#x6570;&#x636E;&#xFF0C;&#x5FC5;&#x987B;&#x4F20;&#x5165; null &#x503C;&#xFF0C;&#x8C03;&#x7528;&#x5B8C;&#x4E4B;&#x540E;&#x8BF7;&#x6C42;&#x5C31;&#x53D1;&#x4F1A;&#x88AB;&#x5206;&#x6D3E;&#x5230;&#x670D;&#x52A1;&#x5668;&#x3002;</li>
</ul>
</li>
</ul>
<p>&#x7531;&#x4E8E;&#x8FD9;&#x6B21;&#x8BF7;&#x6C42;&#x662F;&#x540C;&#x6B65;&#x7684;&#xFF0C;JavaScript &#x4EE3;&#x7801;&#x4F1A;&#x7B49;&#x5230;&#x670D;&#x52A1;&#x5668;&#x54CD;&#x5E94;&#x4E4B;&#x540E;&#x518D;&#x7EE7;&#x7EED;&#x6267;&#x884C;&#x3002;&#x5728;&#x6536;&#x5230;&#x54CD;&#x5E94;&#x540E; &#xFF0C;&#x54CD;&#x5E94;&#x7684;&#x6570;&#x636E;&#x4F1A;&#x81EA;&#x52A8;&#x586B;&#x5145; XHR &#x5BF9;&#x8C61;&#x7684;&#x5C5E;&#x6027;&#x3002;&#x5C5E;&#x6027;&#x8BF4;&#x660E;&#x5982;&#x4E0B;&#xFF1A;</p>
<ul>
<li>responseText: &#x4F5C;&#x4E3A;&#x54CD;&#x5E94;&#x4E3B;&#x4F53;&#x88AB;&#x8FD4;&#x56DE;&#x7684;&#x6587;&#x672C;&#x3002;</li>
<li>responseXML: &#x5982;&#x679C;&#x54CD;&#x5E94;&#x7684;&#x5185;&#x5BB9;&#x662F; &#x201C;text/xml&#x201D; &#x6216; &#x201C;application/xml&#x201D;&#xFF0C;&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x4E2D;&#x4FDD;&#x5B58;&#x7740;&#x54CD;&#x5E94;&#x6570;&#x636E;&#x7684; XML DOM &#x6587;&#x6863;&#x3002; </li>
<li>status: &#x54CD;&#x5E94;&#x7684; HTTP &#x72B6;&#x6001;&#x3002;</li>
<li>statusText: HTTP &#x72B6;&#x6001;&#x8BF4;&#x660E;&#x3002;</li>
</ul>
<p>&#x5728;&#x6536;&#x5230;&#x54CD;&#x5E94;&#x540E;&#xFF0C;&#x7B2C;&#x4E00;&#x6B65;&#x5C31;&#x662F;&#x68C0;&#x67E5; <code>status</code> &#x5C5E;&#x6027;&#xFF0C;&#x4EE5;&#x786E;&#x5B9A;&#x54CD;&#x5E94;&#x5DF2;&#x7ECF;&#x6210;&#x529F;&#x8FD4;&#x56DE;&#x3002;&#x4E00;&#x822C;&#x6765;&#x8BF4;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06; &#x72B6;&#x6001;&#x4EE3;&#x7801;&#x4E3A; 200 &#x4F5C;&#x4E3A;&#x6210;&#x529F;&#x7684;&#x6807;&#x5FD7;&#x3002;&#x6B64;&#x65F6;&#xFF0C;responseText &#x5C5E;&#x6027;&#x7684;&#x5185;&#x5BB9;&#x5DF2;&#x5C31;&#x7EEA;&#xFF0C;&#x800C;&#x4E14;&#x5728;&#x5185;&#x5BB9;&#x6B63;&#x786E;&#x7684;&#x65F6;&#x5019;&#xFF0C;responseXML &#x4E5F;&#x80FD;&#x591F;&#x8BBF;&#x95EE;&#x4E86;&#x3002;&#x6B64;&#x5916;&#xFF0C;&#x72B6;&#x6001;&#x7801;&#x4E3A; 304 &#x8868;&#x793A;&#x8BF7;&#x6C42;&#x7684;&#x8D44;&#x6E90;&#x5E76;&#x6CA1;&#x6709;&#x88AB;&#x4FEE;&#x6539;&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F7F;&#x7528;&#x6D4F;&#x89C8;&#x5668;&#x7F13;&#x5B58;&#x7684;&#x7248;&#x672C;&#xFF1B;&#x4E5F;&#x610F;&#x5473;&#x7740;&#x54CD;&#x5E94;&#x662F;&#x6709;&#x6548;&#x7684;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x68C0;&#x67E5;&#x72B6;&#x6001;&#x7801;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">xhr.open(<span class="string">&quot;get&quot;</span>, <span class="string">&quot;exam.php&quot;</span>, <span class="literal">false</span>);</div><div class="line">xhr.send(<span class="literal">null</span>);</div><div class="line"><span class="keyword">if</span> ((xhr.status &gt;= <span class="number">200</span> &amp;&amp; xhr.status &lt; <span class="number">300</span>) || xhr.status == <span class="number">304</span>) {</div><div class="line">  <span class="built_in">console</span>.log(xhr.responseText);</div><div class="line">} <span class="keyword">else</span> {</div><div class="line">  <span class="built_in">console</span>.log(<span class="string">&quot;&#x8BF7;&#x6C42;&#x5931;&#x8D25;: &quot;</span> + xhr.status);</div><div class="line">}</div></pre></td></tr></table></figure>
<p>&#x524D;&#x9762;&#x8FD9;&#x6837;&#x53D1;&#x9001;&#x540C;&#x6B65;&#x8BF7;&#x6C42;&#x6CA1;&#x6709;&#x95EE;&#x9898;&#xFF0C;&#x4F46;&#x662F;&#x53D1;&#x9001;&#x5F02;&#x6B65;&#x8BF7;&#x6C42;&#x65F6;&#xFF0C;&#x624D;&#x80FD;&#x8BA9; JavaScript &#x7EE7;&#x7EED;&#x6267;&#x884C;&#x800C;&#x4E0D;&#x5FC5;&#x7B49;&#x5F85;&#x54CD;&#x5E94;&#x3002;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x68C0;&#x6D4B; <code>XHR</code> &#x5BF9;&#x8C61;&#x7684; <code>readyState</code> &#x5C5E;&#x6027;&#xFF0C;&#x8BE5;&#x5C5E;&#x6027;&#x8868;&#x793A;&#x8BF7;&#x6C42;/&#x54CD;&#x5E94;&#x8FC7;&#x7A0B;&#x7684;&#x5F53;&#x524D;&#x6D3B;&#x52A8;&#x9636;&#x6BB5;&#x3002;&#x8BE5;&#x5C5E;&#x6027;&#x7684;&#x53D6;&#x503C;&#xFF1A;</p>
<ul>
<li>0 &#x672A;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x5373;&#x5C1A;&#x672A;&#x8C03;&#x7528; open() &#x65B9;&#x6CD5;</li>
<li>1 &#x542F;&#x52A8;&#xFF0C;&#x5DF2;&#x7ECF;&#x8C03;&#x7528; open() &#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x5C1A;&#x672A;&#x8C03;&#x7528; send()</li>
<li>2 &#x53D1;&#x9001;&#xFF0C;&#x5DF2;&#x7ECF;&#x8C03;&#x7528; send() &#x65B9;&#x6CD5;&#xFF0C;&#x4F46;&#x5C1A;&#x672A;&#x63A5;&#x6536;&#x5230;&#x54CD;&#x5E94;&#xFF0C;&#x8BF7;&#x6C42;&#x5DF2;&#x53D1;&#x9001;&#xFF0C;&#x6B63;&#x5728;&#x5904;&#x7406;&#x4E2D;&#xFF08;&#x901A;&#x5E38;&#x73B0;&#x5728;&#x53EF;&#x4EE5;&#x4ECE;&#x54CD;&#x5E94;&#x4E2D;&#x83B7;&#x53D6;&#x5185;&#x5BB9;&#x5934;&#xFF09;&#x3002;</li>
<li>3 &#x63A5;&#x6536;&#xFF0C;&#x5DF2;&#x7ECF;&#x63A5;&#x6536;&#x5230;&#x90E8;&#x5206;&#x54CD;&#x5E94;&#x6570;&#x636E;&#xFF0C;&#x8BF7;&#x6C42;&#x5728;&#x5904;&#x7406;&#x4E2D;&#xFF1B;&#x901A;&#x5E38;&#x54CD;&#x5E94;&#x4E2D;&#x5DF2;&#x6709;&#x90E8;&#x5206;&#x6570;&#x636E;&#x53EF;&#x7528;&#x4E86;&#xFF0C;&#x4F46;&#x662F;&#x670D;&#x52A1;&#x5668;&#x8FD8;&#x6CA1;&#x6709;&#x5B8C;&#x6210;&#x54CD;&#x5E94;&#x7684;&#x751F;&#x6210;&#x3002;</li>
<li>4 &#x5B8C;&#x6210;&#xFF0C;&#x5DF2;&#x7ECF;&#x63A5;&#x6536;&#x5230;&#x5168;&#x90E8;&#x54CD;&#x5E94;&#x6570;&#x636E;&#xFF0C;&#x800C;&#x4E14;&#x5DF2;&#x7ECF;&#x53EF;&#x4EE5;&#x5728;&#x5BA2;&#x6237;&#x7AEF;&#x4F7F;&#x7528;&#x4E86;</li>
</ul>
<p>&#x53EA;&#x8981; <code>readyState</code> &#x5C5E;&#x6027;&#x7684;&#x503C;&#x7531;&#x4E00;&#x4E2A;&#x503C;&#x53D8;&#x6210;&#x53E6;&#x4E00;&#x4E2A;&#x503C;&#xFF0C;&#x90FD;&#x4F1A;&#x89E6;&#x53D1; <code>readystatechange</code> &#x4E8B;&#x4EF6;&#x3002;&#x53EF;&#x4EE5;&#x5229;&#x7528;&#x8FD9;&#x4E2A;&#x4E8B;&#x4EF6;&#x6765;&#x68C0;&#x6D4B;&#x6BCF;&#x6B21;&#x72B6;&#x6001;&#x53D8;&#x5316;&#x540E; <code>readyState</code> &#x503C;&#x3002;&#x901A;&#x5E38;&#xFF0C;&#x6211;&#x4EEC;&#x53EA;&#x5BF9; <code>readyState</code> &#x503C;&#x4E3A; 4 &#x7684;&#x9636;&#x6BB5;&#x611F;&#x5174;&#x8DA3;&#xFF0C;&#x56E0;&#x4E3A;&#x8FD9;&#x65F6;&#x6240;&#x6709;&#x6570;&#x636E;&#x90FD;&#x5DF2;&#x7ECF;&#x5C31;&#x7EEA;&#x3002;&#x4E0D;&#x8FC7;&#xFF0C;&#x5FC5;&#x987B;&#x5728;&#x8C03;&#x7528; <code>open()</code> &#x4E4B;&#x524D;&#x6307;&#x5B9A; <code>onreadystatechange</code> &#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;&#x624D;&#x80FD;&#x786E;&#x4FDD;&#x8DE8;&#x6D4F;&#x89C8;&#x5668;&#x517C;&#x5BB9;&#x6027;&#x3002;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;<code>onreadystatechange</code> &#x662F; <code>Javascript&#x7684;</code> &#x4E8B;&#x4EF6;&#x7684;&#x4E00;&#x79CD;&#xFF0C;&#x5176;&#x610F;&#x4E49;&#x5728;&#x4E8E;&#x76D1;&#x542C; <code>XMLHttpRequest</code> &#x7684;&#x72B6;&#x6001;</p>
<ul>
<li>&#x83B7;&#x53D6;&#x72B6;&#x6001;&#x884C;&#xFF08;&#x5305;&#x62EC;&#x72B6;&#x6001;&#x7801;&amp;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#xFF09;<ul>
<li><code>xhr.status</code> &#x72B6;&#x6001;&#x7801;; </li>
<li><code>xhr.statusText</code> &#x72B6;&#x6001;&#x7801;&#x4FE1;&#x606F; </li>
</ul>
</li>
<li>&#x83B7;&#x53D6;&#x54CD;&#x5E94;&#x5934; <ul>
<li><code>xhr.getResponseHeader(&apos;Content-Type&apos;)</code>; </li>
<li><code>xhr.getAllResponseHeaders()</code>;</li>
</ul>
</li>
<li>&#x54CD;&#x5E94;&#x4E3B;&#x4F53; <ul>
<li><code>xhr.responseText</code>; </li>
<li><code>xhr.responseXML</code></li>
</ul>
</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> xhr = createXHR();</div><div class="line">xhr.onreadystatechange = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</div><div class="line">  <span class="keyword">if</span> (xhr.readState == <span class="number">4</span>) {</div><div class="line">    <span class="keyword">if</span> ((xhr.status &gt;= <span class="number">200</span> &amp;&amp; xhr.status &lt; <span class="number">300</span>) || xhr.status == <span class="number">304</span>) {</div><div class="line">      <span class="built_in">console</span>.log(xhr.responseText);</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      <span class="built_in">console</span>.log(<span class="string">&quot;&#x8BF7;&#x6C42;&#x5931;&#x8D25;: &quot;</span> + xhr.status);</div><div class="line">    }</div><div class="line">  }</div><div class="line">};</div><div class="line">xhr.open(<span class="string">&quot;get&quot;</span>, <span class="string">&quot;exam.php&quot;</span>, <span class="literal">true</span>);</div><div class="line">xhr.send(<span class="literal">null</span>);</div></pre></td></tr></table></figure>
<p>&#x5728;&#x63A5;&#x6536;&#x5230;&#x54CD;&#x5E94;&#x4E4B;&#x524D;&#x8FD8;&#x53EF;&#x4EE5;&#x8C03;&#x7528; <code>abort()</code> &#x65B9;&#x6CD5;&#x6765;&#x53D6;&#x6D88;&#x5F02;&#x6B65;&#x8BF7;&#x6C42;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">xhr.abort();</div></pre></td></tr></table></figure>
<p><code>setRequestHeader()</code>&#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x8BF7;&#x6C42;&#x5934;&#x90E8;&#x4FE1;&#x606F;&#x3002;&#x8FD9;&#x4E2A;&#x65B9;&#x6CD5;&#x63A5;&#x6536;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;</p>
<ul>
<li>&#x5934;&#x90E8;&#x540D;&#x79F0;</li>
<li>&#x5934;&#x90E8;&#x5B57;&#x6BB5;&#x7684;&#x503C;</li>
</ul>
<p><code>setRequestHeader()</code>&#x65B9;&#x6CD5;&#x5FC5;&#x987B;&#x5728;&#x8C03;&#x7528; open() &#x65B9;&#x6CD5;&#x4E4B;&#x540E;&#xFF0C;send() &#x65B9;&#x6CD5;&#x4E4B;&#x524D;&#x8C03;&#x7528;.</p>
<h3 id="GET-&#x8BF7;&#x6C42;"><a href="#GET-&#x8BF7;&#x6C42;" class="headerlink" title="GET &#x8BF7;&#x6C42;"></a>GET &#x8BF7;&#x6C42;</h3><p>GET &#x8BF7;&#x6C42;&#x5C06;&#x67E5;&#x8BE2;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x53C2;&#x6570;&#x8FFD;&#x52A0;&#x5230; URL &#x7684;&#x672B;&#x5C3E;&#xFF0C;&#x4F20;&#x5165; open() &#x65B9;&#x6CD5;&#x7684; URL &#x672B;&#x5C3E;&#x7684;&#x67E5;&#x8BE2;&#x5B57;&#x7B26;&#x4E32;&#x5FC5;&#x987B;&#x7ECF;&#x8FC7;&#x6B63;&#x786E;&#x7684;&#x7F16;&#x7801;&#x624D;&#x884C;&#x3002;</p>
<p>&#x67E5;&#x8BE2;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x7684;&#x6BCF;&#x4E2A;&#x503C;&#x90FD;&#x5FC5;&#x987B;&#x7ECF;&#x8FC7; encodeURLComponent() &#x8FDB;&#x884C;&#x7F16;&#x7801;&#xFF0C;&#x7136;&#x540E;&#x624D;&#x80FD;&#x653E;&#x5230; URL &#x672B;&#x5C3E;&#x3002;</p>
<p>&#x6240;&#x6709;&#x7684;&#x540D;-&#x503C;&#x5BF9;&#x90FD;&#x5FC5;&#x987B;&#x7531;&#xFF08;&amp;&#xFF09;&#x7B26;&#x53F7;&#x5206;&#x9694;&#x3002;&#x5982;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">xhr.open(<span class="string">&quot;get&quot;</span>, <span class="string">&quot;exam.php?name=value&amp;name=value2&quot;</span>, <span class="literal">true</span>);</div></pre></td></tr></table></figure>
<p>&#x5C01;&#x88C5;&#x7ECF;&#x8FC7;&#x7F16;&#x7801;&#x7684;&#x67E5;&#x8BE2;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="comment">// &#x5411; URL &#x672B;&#x5C3E;&#x6DFB;&#x52A0;&#x67E5;&#x8BE2;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x65B9;&#x6CD5;</span></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">addURLParam</span>(<span class="params">url, name, value</span>) </span>{</div><div class="line">  url += (url.indexOf(<span class="string">&quot;?&quot;</span>) == <span class="number">-1</span> ? <span class="string">&quot;?&quot;</span> : <span class="string">&quot;&amp;&quot;</span>);</div><div class="line">  url += encodeURLComponent(name) + <span class="string">&quot;=&quot;</span> + encodeURLComponent(value);</div><div class="line">  <span class="keyword">return</span> url;</div><div class="line">}</div></pre></td></tr></table></figure>
<h3 id="POST-&#x8BF7;&#x6C42;"><a href="#POST-&#x8BF7;&#x6C42;" class="headerlink" title="POST &#x8BF7;&#x6C42;"></a>POST &#x8BF7;&#x6C42;</h3><p>&#x901A;&#x5E38;&#x7528;&#x4E8E;&#x5411;&#x670D;&#x52A1;&#x5668;&#x53D1;&#x9001;&#x5E94;&#x8BE5;&#x4FDD;&#x5B58;&#x7684;&#x6570;&#x636E;&#x3002;POST &#x8BF7;&#x6C42;&#x5E94;&#x8BE5;&#x628A;&#x6570;&#x636E;&#x4F5C;&#x4E3A;&#x8BF7;&#x6C42;&#x7684;&#x4E3B;&#x4F53;&#x63D0;&#x4EA4;&#x3002;&#x7ED9; open() &#x65B9;&#x6CD5;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x4F20;&#x5165; &#x201C;post&#x201D; &#x5C31;&#x53EF;&#x4EE5;&#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A; post &#x8BF7;&#x6C42;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">xhr.open(<span class="string">&quot;post&quot;</span>, <span class="string">&quot;exam.php&quot;</span>, <span class="literal">true</span>);</div></pre></td></tr></table></figure>
<p>&#x4F7F;&#x7528; XHR &#x6765;&#x6A21;&#x4EFF;&#x8868;&#x5355;&#x63D0;&#x4EA4;&#xFF1A;&#x9996;&#x5148;&#x5C06; <code>Content-Type</code> &#x5934;&#x90E8;&#x8BBE;&#x7F6E;&#x4E3A; <code>application/x-www-form-urlencoded</code> &#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8868;&#x5355;&#x63D0;&#x4EA4;&#x65F6;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x5176;&#x6B21;&#x662F;&#x4EE5;&#x9002;&#x5F53;&#x7684;&#x683C;&#x5F0F;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">submitData</span>(<span class="params"></span>) </span>{</div><div class="line">  <span class="keyword">var</span> xhr = createXHR();</div><div class="line">  xhr.onreadstatechange = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</div><div class="line">    <span class="keyword">if</span> (xhr.readyState == <span class="number">4</span>) {</div><div class="line">      <span class="keyword">if</span> ((xhr.status &gt;= <span class="number">200</span> &amp;&amp; xhr.status &lt; <span class="number">300</span>) || xhr.status == <span class="number">304</span>) {</div><div class="line">        <span class="built_in">console</span>.log(xhr.responseText);</div><div class="line">      } <span class="keyword">else</span> {</div><div class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;&#x8BF7;&#x6C42;&#x5931;&#x8D25;: &quot;</span> + xhr.status);</div><div class="line">      }</div><div class="line">    }</div><div class="line">  };</div><div class="line">  xhr.open(<span class="string">&quot;post&quot;</span>, <span class="string">&quot;exam.php&quot;</span>, <span class="literal">true</span>);</div><div class="line">  xhr.setRequestHeader(<span class="string">&quot;Content-Type&quot;</span>, <span class="string">&quot;application/x-www-form-urlencoded&quot;</span>);</div><div class="line">  <span class="keyword">var</span> form = <span class="built_in">document</span>.getElementById(<span class="string">&quot;userInfo&quot;</span>);</div><div class="line">  xhr.send(serialize(form));</div><div class="line">}</div><div class="line"><span class="comment">// &#x83B7;&#x53D6; XHR &#x5BF9;&#x8C61;&#x7684;&#x517C;&#x5BB9;&#x65B9;&#x6CD5;</span></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">createXHR</span>(<span class="params"></span>) </span>{</div><div class="line">  <span class="keyword">if</span> (<span class="keyword">typeof</span> <span class="built_in">arguments</span>.callee.activeXString != <span class="string">&quot;string&quot;</span>) {</div><div class="line">    <span class="keyword">var</span> versions = [</div><div class="line">      <span class="string">&quot;MSXML2.XMLHttp.6.0&quot;</span>,</div><div class="line">      <span class="string">&quot;MSXML2.XMLHttp.3.0&quot;</span>,</div><div class="line">      <span class="string">&quot;MSXML2.XMLHtt&quot;</span></div><div class="line">    ], i, len;</div><div class="line">    <span class="keyword">for</span> (i = <span class="number">0</span>, len = versions.length; i &lt; len; i++) {</div><div class="line">      <span class="keyword">try</span> {</div><div class="line">        <span class="keyword">new</span> ActiveXObject(versions[i]);</div><div class="line">        <span class="built_in">arguments</span>.callee.activeXString = versions[i];</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">      } <span class="keyword">catch</span> (ex) {</div><div class="line">        <span class="comment">// &#x8DF3;&#x8FC7;</span></div><div class="line">      }</div><div class="line">    }</div><div class="line">  }</div><div class="line">  <span class="keyword">return</span> <span class="keyword">new</span> ActiveXObject(<span class="built_in">arguments</span>.callee.activeXString);</div><div class="line">}</div><div class="line"><span class="comment">// &#x8868;&#x5355;&#x5E8F;&#x5217;&#x5316;&#x51FD;&#x6570;</span></div><div class="line"><span class="function"><span class="keyword">function</span> <span class="title">serialize</span>(<span class="params">form</span>) </span>{</div><div class="line">  <span class="keyword">var</span> parts = [],</div><div class="line">    field = <span class="literal">null</span>,</div><div class="line">    i,</div><div class="line">    len,</div><div class="line">    j,</div><div class="line">    optLen,</div><div class="line">    option,</div><div class="line">    optValue;</div><div class="line">  <span class="keyword">for</span> (i = <span class="number">0</span>, len = form.elements.length; i &lt; len; i++) {</div><div class="line">    field = form.elements[i];</div><div class="line">    <span class="keyword">switch</span>(field.type) {</div><div class="line">      <span class="keyword">case</span> <span class="string">&quot;select-one&quot;</span>:</div><div class="line">      <span class="keyword">case</span> <span class="string">&quot;select-multipule&quot;</span>:</div><div class="line">        <span class="keyword">if</span> (field.name.length) {</div><div class="line">          <span class="keyword">for</span> (j = <span class="number">0</span>, optLen = field.options.length; j &lt; optLen; j++) {</div><div class="line">            option = field.options[j];</div><div class="line">            <span class="keyword">if</span> (option.selected) {</div><div class="line">              optValue = <span class="string">&quot;&quot;</span>;</div><div class="line">              <span class="keyword">if</span> (option.hasAttribute) {</div><div class="line">                optValue = (option.hasAttribute(<span class="string">&quot;value&quot;</span>) ? option.value : option.text);</div><div class="line">              } <span class="keyword">else</span> {</div><div class="line">                optValue = (option.attributes[<span class="string">&quot;values&quot;</span>].specified ? option.value : option.text);</div><div class="line">              }</div><div class="line">              parts.push(encodeURLComponent(field.name) + <span class="string">&quot;=&quot;</span> + encodeURLComponent(optValue));</div><div class="line">            }</div><div class="line">          }</div><div class="line">        }</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">      <span class="keyword">case</span> <span class="literal">undefined</span>:</div><div class="line">      <span class="keyword">case</span> <span class="string">&quot;file&quot;</span>:</div><div class="line">      <span class="keyword">case</span> <span class="string">&quot;reset&quot;</span>:</div><div class="line">      <span class="keyword">case</span> <span class="string">&quot;submit&quot;</span>:</div><div class="line">      <span class="keyword">case</span> <span class="string">&quot;button&quot;</span>:</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">      <span class="keyword">case</span> <span class="string">&quot;radio&quot;</span>:</div><div class="line">      <span class="keyword">case</span> <span class="string">&quot;checkbox&quot;</span>:</div><div class="line">        <span class="keyword">if</span> (!field.name.length) {</div><div class="line">          <span class="keyword">break</span>;</div><div class="line">        }</div><div class="line">      <span class="keyword">default</span>:</div><div class="line">        <span class="keyword">if</span> (field.name.length) {</div><div class="line">          parts.push(encodeURLComponent(field.name) + <span class="string">&quot;=&quot;</span> + encodeURLComponent(field.value));</div><div class="line">        }</div><div class="line">    }</div><div class="line">  }</div><div class="line">  <span class="keyword">return</span> parts.join(<span class="string">&quot;&amp;&quot;</span>);</div><div class="line">}</div></pre></td></tr></table></figure>
<p><strong>&#x6CE8;&#xFF1A;GET&#x548C;POST&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#x7684;&#x5DEE;&#x5F02;</strong></p>
<ul>
<li>GET&#x6CA1;&#x6709;&#x8BF7;&#x6C42;&#x4E3B;&#x4F53;&#xFF0C;&#x4F7F;&#x7528;xhr.send(null)</li>
<li>GET&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5728;&#x8BF7;&#x6C42;URL&#x4E0A;&#x6DFB;&#x52A0;&#x8BF7;&#x6C42;&#x53C2;&#x6570;</li>
<li>POST&#x53EF;&#x4EE5;&#x901A;&#x8FC7;xhr.send(&#x2018;name=itcast&amp;age=10&#x2019;)</li>
<li>POST&#x9700;&#x8981;&#x8BBE;&#x7F6E;</li>
<li>GET&#x6548;&#x7387;&#x66F4;&#x597D;&#xFF08;&#x5E94;&#x7528;&#x591A;&#xFF09;</li>
<li>GET&#x5927;&#x5C0F;&#x9650;&#x5236;&#x7EA6;4K&#xFF0C;POST&#x5219;&#x6CA1;&#x6709;&#x9650;&#x5236;</li>
</ul>
<h3 id="&#x5173;&#x4E8E;&#x8868;&#x5355;&#x5E8F;&#x5217;&#x5316;"><a href="#&#x5173;&#x4E8E;&#x8868;&#x5355;&#x5E8F;&#x5217;&#x5316;" class="headerlink" title="&#x5173;&#x4E8E;&#x8868;&#x5355;&#x5E8F;&#x5217;&#x5316;"></a>&#x5173;&#x4E8E;&#x8868;&#x5355;&#x5E8F;&#x5217;&#x5316;</h3><p>XMLHTTPRequest 2 &#x7EA7; &#x5B9A;&#x4E49;&#x4E86; FormData &#x7C7B;&#x578B;&#x3002; FormData &#x4E3A;&#x5E8F;&#x5217;&#x5316;&#x8868;&#x5355;&#x4EE5;&#x53CA;&#x521B;&#x5EFA;&#x4E0E;&#x8868;&#x5355;&#x683C;&#x5F0F;&#x76F8;&#x540C;&#x7684;&#x6570;&#x636E;&#x3002;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> data <span class="keyword">new</span> FormData();</div><div class="line">data.append(<span class="string">&quot;name&quot;</span>, <span class="string">&quot;Hiraku&quot;</span>);</div></pre></td></tr></table></figure>
<p>append() &#x65B9;&#x6CD5;&#x4F20;&#x9012;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x3002;&#x5373;&#x952E;&#x548C;&#x503C;&#x3002;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5982;&#x4E0B;&#x7684;&#x65B9;&#x5F0F;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> data = <span class="keyword">new</span> FormData(<span class="built_in">document</span>.forms[<span class="number">0</span>]);</div></pre></td></tr></table></figure>
<p>&#x521B;&#x5EFA;&#x4E86; FormData &#x7684;&#x5B9E;&#x4F8B;&#x540E;&#xFF0C;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x4F20;&#x9012;&#x7ED9; send() &#x65B9;&#x6CD5;&#xFF1A;</p>
<figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> xhr = createXHR();</div><div class="line">xhr.onreadstatechange = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</div><div class="line">  <span class="keyword">if</span> (xhr.readyState == <span class="number">4</span>) {</div><div class="line">    <span class="keyword">if</span> ((xhr.status &gt;= <span class="number">200</span> &amp;&amp; xhr.status &lt; <span class="number">300</span>) || xhr.status == <span class="number">304</span>) {</div><div class="line">      <span class="built_in">console</span>.log(xhr.responseText);</div><div class="line">    } <span class="keyword">else</span> {</div><div class="line">      <span class="built_in">console</span>.log(<span class="string">&quot;&#x8BF7;&#x6C42;&#x5931;&#x8D25;: &quot;</span> + xhr.status);</div><div class="line">    }</div><div class="line">  }</div><div class="line">};</div><div class="line">xhr.open(<span class="string">&quot;post&quot;</span>, <span class="string">&quot;exam.php&quot;</span>, <span class="literal">true</span>);</div><div class="line">xhr.setRequestHeader(<span class="string">&quot;Content-Type&quot;</span>, <span class="string">&quot;application/x-www-form-urlencoded&quot;</span>);</div><div class="line"><span class="keyword">var</span> form = <span class="built_in">document</span>.getElementById(<span class="string">&quot;userInfo&quot;</span>);</div><div class="line">xhr.send(<span class="keyword">new</span> FormDta(form));</div></pre></td></tr></table></figure>
<h3 id="&#x8D85;&#x65F6;&#x8BBE;&#x5B9A;"><a href="#&#x8D85;&#x65F6;&#x8BBE;&#x5B9A;" class="headerlink" title="&#x8D85;&#x65F6;&#x8BBE;&#x5B9A;"></a>&#x8D85;&#x65F6;&#x8BBE;&#x5B9A;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">var</span> xhr = createXHR();</div><div class="line">xhr.onreadstatechange = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>{</div><div class="line">  <span class="keyword">try</span> {</div><div class="line">    <span class="keyword">if</span> (xhr.readyState == <span class="number">4</span>) {</div><div class="line">      <span class="keyword">if</span> ((xhr.status &gt;= <span class="number">200</span> &amp;&amp; xhr.status &lt; <span class="number">300</span>) || xhr.status == <span class="number">304</span>) {</div><div class="line">        <span class="built_in">console</span>.log(xhr.responseText);</div><div class="line">      } <span class="keyword">else</span> {</div><div class="line">        <span class="built_in">console</span>.log(<span class="string">&quot;&#x8BF7;&#x6C42;&#x5931;&#x8D25;: &quot;</span> + xhr.status);</div><div class="line">      }</div><div class="line">    }</div><div class="line">    } <span class="keyword">catch</span> (e) {</div><div class="line">      <span class="comment">// &#x7531; ontimeout &#x4E8B;&#x4EF6;&#x7A0B;&#x5E8F;&#x5904;&#x7406;</span></div><div class="line">    }</div><div class="line">  </div><div class="line">};</div><div class="line">xhr.open(<span class="string">&quot;get&quot;</span>, <span class="string">&quot;exam.php&quot;</span>, <span class="literal">true</span>);</div><div class="line">xht.timeout = <span class="number">1000</span>; <span class="comment">// &#x4EC5;&#x9002;&#x7528;&#x4E8E; IE</span></div><div class="line">xhr.ontimeout = funciton() {</div><div class="line">  <span class="built_in">console</span>.log(<span class="string">&quot;&#x8BF7;&#x6C42;&#x5931;&#x8D25;&#xFF1A;&quot;</span>)</div><div class="line">}</div><div class="line">xhr.send(<span class="literal">null</span>);</div></pre></td></tr></table></figure>
<h3 id="&#x8FDB;&#x5EA6;&#x4E8B;&#x4EF6;"><a href="#&#x8FDB;&#x5EA6;&#x4E8B;&#x4EF6;" class="headerlink" title="&#x8FDB;&#x5EA6;&#x4E8B;&#x4EF6;"></a>&#x8FDB;&#x5EA6;&#x4E8B;&#x4EF6;</h3><ul>
<li>loadstart: &#x6536;&#x5230;&#x54CD;&#x5E94;&#x6570;&#x636E;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x8282;&#x65F6;&#x89E6;&#x53D1;</li>
<li>progress&#xFF1A;&#x5728;&#x63A5;&#x6536;&#x54CD;&#x5E94;&#x671F;&#x95F4;&#x4E0D;&#x65AD;&#x5730;&#x89E6;&#x53D1;</li>
<li>error: &#x53D1;&#x751F;&#x9519;&#x8BEF;&#x65F6;&#x89E6;&#x53D1;</li>
<li>abort: &#x8C03;&#x7528; abort() &#x65B9;&#x6CD5;&#x800C;&#x7EC8;&#x6B62;&#x65F6;&#x89E6;&#x53D1;</li>
<li>load: &#x5728;&#x63A5;&#x6536;&#x5230;&#x5B8C;&#x6574;&#x7684;&#x54CD;&#x5E94;&#x6570;&#x636E;&#x65F6;&#x89E6;&#x53D1;</li>
<li>loadend: &#x5728;&#x901A;&#x4FE1;&#x5B8C;&#x6210;&#x6216;&#x8005;&#x89E6;&#x53D1; error&#x3001;abort&#x3001;&#x6216; load &#x4E8B;&#x4EF6;&#x540E;&#x89E6;&#x53D1;&#x3002;</li>
</ul>
<p>&#x6211;&#x4EEC;&#x9700;&#x8981;&#x68C0;&#x6D4B;&#x5E76;&#x5224;&#x65AD;&#x54CD;&#x5E94;&#x5934;&#x7684; MIME &#x7C7B;&#x578B;&#x540E;&#x786E;&#x5B9A;&#x4F7F;&#x7528; <code>request.responseText</code> &#x6216;&#x8005; <code>request.responseXML</code></p>
<h3 id="API-&#x603B;&#x7ED3;"><a href="#API-&#x603B;&#x7ED3;" class="headerlink" title="API &#x603B;&#x7ED3;"></a>API &#x603B;&#x7ED3;</h3><ul>
<li><code>xhr.open()</code> <ul>
<li>&#x53D1;&#x8D77;&#x8BF7;&#x6C42;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;get&#x3001;post&#x65B9;&#x5F0F;</li>
</ul>
</li>
<li><code>xhr.setRequestHeader()</code> <ul>
<li>&#x8BBE;&#x7F6E;&#x8BF7;&#x6C42;&#x5934;</li>
</ul>
</li>
<li><code>xhr.send()</code> <ul>
<li>&#x53D1;&#x9001;&#x8BF7;&#x6C42;&#x4E3B;&#x4F53;get&#x65B9;&#x5F0F;&#x4F7F;&#x7528;xhr.send(null)</li>
</ul>
</li>
<li><code>xhr.onreadystatechange = function () {}</code> <ul>
<li>&#x76D1;&#x542C;&#x54CD;&#x5E94;&#x72B6;&#x6001;</li>
</ul>
</li>
<li><code>xhr.status</code> <ul>
<li>&#x8868;&#x793A;&#x54CD;&#x5E94;&#x7801;&#xFF0C;&#x5982;200</li>
</ul>
</li>
<li><code>xhr.statusText</code> <ul>
<li>&#x8868;&#x793A;&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#xFF0C;&#x5982;OK</li>
</ul>
</li>
<li><code>xhr.getAllResponseHeaders()</code> <ul>
<li>&#x83B7;&#x53D6;&#x5168;&#x90E8;&#x54CD;&#x5E94;&#x5934;&#x4FE1;&#x606F;</li>
</ul>
</li>
<li><code>xhr.getResponseHeader(&apos;key&apos;)</code> <ul>
<li>&#x83B7;&#x53D6;&#x6307;&#x5B9A;&#x5934;&#x4FE1;&#x606F;</li>
</ul>
</li>
<li><code>xhr.responseText&#x3001;xhr.responseXML</code><ul>
<li>&#x90FD;&#x8868;&#x793A;&#x54CD;&#x5E94;&#x4E3B;&#x4F53;</li>
</ul>
</li>
</ul>
<h3 id="&#x5C01;&#x88C5;ajax&#x5DE5;&#x5177;&#x51FD;&#x6570;"><a href="#&#x5C01;&#x88C5;ajax&#x5DE5;&#x5177;&#x51FD;&#x6570;" class="headerlink" title="&#x5C01;&#x88C5;ajax&#x5DE5;&#x5177;&#x51FD;&#x6570;"></a>&#x5C01;&#x88C5;ajax&#x5DE5;&#x5177;&#x51FD;&#x6570;</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/*</span></div><div class="line"> * 1. &#x8BF7;&#x6C42;&#x7684;&#x7C7B;&#x578B;                type    get post</div><div class="line"> * 2. &#x8BF7;&#x6C42;&#x5730;&#x5740;                  url</div><div class="line"> * 3. &#x662F;&#x5F02;&#x6B65;&#x7684;&#x8FD8;&#x662F;&#x540C;&#x6B65;&#x7684;         async   false true</div><div class="line"> * 4. &#x8BF7;&#x6C42;&#x5185;&#x5BB9;&#x7684;&#x683C;&#x5F0F;            contentType</div><div class="line"> * 5. &#x4F20;&#x8F93;&#x7684;&#x6570;&#x636E;                data    json&#x5BF9;&#x8C61;</div><div class="line"> * 6. &#x54CD;&#x5E94;&#x6210;&#x529F;&#x5904;&#x7406;&#x51FD;&#x6570;           success   function</div><div class="line"> * 7. &#x54CD;&#x5E94;&#x5931;&#x8D25;&#x7684;&#x5904;&#x7406;&#x51FD;&#x6570;         error     function</div><div class="line"> * &#x8FD9;&#x4E9B;&#x90FD;&#x662F;&#x52A8;&#x6001;&#x53C2;&#x6570;  &#x53C2;&#x6570;&#x5BF9;&#x8C61;  options</div><div class="line"> * */</div><div class="line"><span class="built_in">window</span>.$ = {};<span class="comment">/*&#x5C01;&#x88C5;&#x4E00;&#x4E2A;&#x51FD;&#x6570;*/</span></div><div class="line"><span class="comment">/*&#x7533;&#x660E;&#x4E00;&#x4E2A;ajax&#x7684;&#x65B9;&#x6CD5;*/</span></div><div class="line">$.ajax = <span class="function"><span class="keyword">function</span>(<span class="params">options</span>)</span>{</div><div class="line">    <span class="keyword">if</span>(!options || <span class="keyword">typeof</span> options != <span class="string">&apos;object&apos;</span>){</div><div class="line">        <span class="keyword">return</span> <span class="literal">false</span>;</div><div class="line">    }</div><div class="line">    <span class="comment">/*&#x8BF7;&#x6C42;&#x7684;&#x7C7B;&#x578B;*/</span></div><div class="line">    <span class="keyword">var</span> type = options.type || <span class="string">&apos;get&apos;</span>;<span class="comment">/*&#x9ED8;&#x8BA4;get*/</span></div><div class="line">    <span class="comment">/*&#x8BF7;&#x6C42;&#x5730;&#x5740; */</span></div><div class="line">    <span class="keyword">var</span> url = options.url || location.pathname;<span class="comment">/*&#x5F53;&#x524D;&#x7684;&#x5730;&#x5740;*/</span></div><div class="line">    <span class="comment">/*&#x662F;&#x5F02;&#x6B65;&#x7684;&#x8FD8;&#x662F;&#x540C;&#x6B65;&#x7684; */</span></div><div class="line">    <span class="keyword">var</span> <span class="keyword">async</span> = (options.async === <span class="literal">false</span>)?<span class="literal">false</span>:<span class="literal">true</span>;<span class="comment">/*&#x9ED8;&#x8BA4;&#x5F02;&#x6B65;*/</span></div><div class="line">    <span class="comment">/*&#x8BF7;&#x6C42;&#x5185;&#x5BB9;&#x7684;&#x683C;&#x5F0F; */</span></div><div class="line">    <span class="keyword">var</span> contentType = options.contentType || <span class="string">&quot;text/html&quot;</span>;</div><div class="line">    <span class="comment">/*&#x4F20;&#x8F93;&#x7684;&#x6570;&#x636E; */</span></div><div class="line">    <span class="keyword">var</span> data = options.data || {};<span class="comment">/*&#xFF5B;name:&apos;&apos;,age:&apos;&apos;&#xFF5D;*/</span></div><div class="line">    <span class="comment">/*&#x5728;&#x63D0;&#x4EA4;&#x7684;&#x65F6;&#x5019;&#x9700;&#x8981;&#x8F6C;&#x6210; name=xjj &#x8FD9;&#x79CD;&#x683C;&#x5F0F;*/</span></div><div class="line">    <span class="keyword">var</span> dataStr = <span class="string">&apos;&apos;</span>; <span class="comment">/*&#x6570;&#x636E;&#x5B57;&#x7B26;&#x4E32;*/</span></div><div class="line">    <span class="keyword">for</span>(<span class="keyword">var</span> key <span class="keyword">in</span> data){</div><div class="line">        dataStr += key+<span class="string">&apos;=&apos;</span>+data[key]+<span class="string">&apos;&amp;&apos;</span>;</div><div class="line">    }</div><div class="line">    dataStr = dataStr &amp;&amp; dataStr.slice(<span class="number">0</span>,<span class="number">-1</span>);</div><div class="line">    <span class="comment">/*ajax &#x7F16;&#x7A0B;*/</span></div><div class="line">    <span class="keyword">var</span> xhr = <span class="keyword">new</span> XMLHttpRequest();</div><div class="line">    <span class="comment">/*&#x8BF7;&#x6C42;&#x884C;*/</span></div><div class="line">    <span class="comment">/*(type==&apos;get&apos;?url+&apos;?&apos;+dataStr:url)&#x5224;&#x65AD;&#x5F53;&#x524D;&#x7684;&#x8BF7;&#x6C42;&#x7C7B;&#x578B;*/</span></div><div class="line">    xhr.open(type,(type==<span class="string">&apos;get&apos;</span>?url+<span class="string">&apos;?&apos;</span>+dataStr:url),<span class="keyword">async</span>);</div><div class="line">    <span class="comment">/*&#x8BF7;&#x6C42;&#x5934;*/</span></div><div class="line">    <span class="keyword">if</span>(type == <span class="string">&apos;post&apos;</span>){</div><div class="line">        xhr.setRequestHeader(<span class="string">&apos;Content-Type&apos;</span>,<span class="string">&apos;application/x-www-form-urlencoded&apos;</span>);</div><div class="line">    }</div><div class="line">    <span class="comment">/*&#x8BF7;&#x6C42;&#x4E3B;&#x4F53;*/</span></div><div class="line">    <span class="comment">/*&#x9700;&#x8981;&#x5224;&#x65AD;&#x8BF7;&#x6C42;&#x7C7B;&#x578B;*/</span></div><div class="line">    xhr.send(type==<span class="string">&apos;get&apos;</span>?<span class="literal">null</span>:dataStr);</div><div class="line">    <span class="comment">/*&#x76D1;&#x542C;&#x54CD;&#x5E94;&#x72B6;&#x6001;&#x7684;&#x6539;&#x53D8;  &#x54CD;&#x5E94;&#x72B6;&#x6001;*/</span></div><div class="line">    xhr.onreadystatechange = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>{</div><div class="line">        <span class="comment">/*&#x8BF7;&#x6C42;&#x54CD;&#x5E94;&#x5B8C;&#x6210;&#x5E76;&#x4E14;&#x6210;&#x529F;*/</span></div><div class="line">        <span class="keyword">if</span>(xhr.readyState == <span class="number">4</span> &amp;&amp; xhr.status == <span class="number">200</span>){</div><div class="line">            <span class="comment">/*success*/</span></div><div class="line">            <span class="keyword">var</span> data = <span class="string">&apos;&apos;</span>;</div><div class="line">            <span class="keyword">var</span> contentType = xhr.getResponseHeader(<span class="string">&apos;Content-Type&apos;</span>);</div><div class="line">            <span class="comment">/*&#x5982;&#x679C;&#x6211;&#x4EEC;&#x670D;&#x52A1;&#x5668;&#x8FD4;&#x56DE;&#x7684;&#x662F;xml*/</span></div><div class="line">            <span class="keyword">if</span>(contentType.indexOf(<span class="string">&apos;xml&apos;</span>) &gt; <span class="number">-1</span>){</div><div class="line">                data = xhr.responseXML;</div><div class="line">            }</div><div class="line">            <span class="comment">/*&#x5982;&#x679C;&#x6211;&#x4EEC;&#x7684;&#x670D;&#x52A1;&#x5668;&#x8FD4;&#x56DE;&#x7684;&#x662F;json&#x5B57;&#x7B26;&#x4E32;*/</span></div><div class="line">            <span class="keyword">else</span> <span class="keyword">if</span>(contentType.indexOf(<span class="string">&apos;json&apos;</span>) &gt; <span class="number">-1</span>){</div><div class="line">                <span class="comment">/*&#x8F6C;&#x5316;json&#x5BF9;&#x8C61;*/</span></div><div class="line">                data = <span class="built_in">JSON</span>.parse(xhr.responseText);</div><div class="line">            }</div><div class="line">            <span class="comment">/*&#x5426;&#x5219;&#x7684;&#x8BDD;&#x4ED6;&#x5C31;&#x662F;&#x5B57;&#x7B26;&#x4E32;*/</span></div><div class="line">            <span class="keyword">else</span>{</div><div class="line">                data = xhr.responseText;</div><div class="line">            }</div><div class="line">            <span class="comment">/*&#x56DE;&#x8C03; &#x6210;&#x529F;&#x5904;&#x7406;&#x51FD;&#x6570;*/</span></div><div class="line">            options.success &amp;&amp; options.success(data);</div><div class="line">        }</div><div class="line">        <span class="comment">/*&#x8BA1;&#x65F6;&#x8BF7;&#x6C42;xhr.status&#x4E0D;&#x6210;&#x529F;  &#x4ED6;&#x4E5F;&#x9700;&#x8981;&#x7684;&#x54CD;&#x5E94;&#x5B8C;&#x6210;&#x624D;&#x8BA4;&#x4F5C;&#x662F;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x7684;&#x8BF7;&#x6C42;*/</span></div><div class="line">        <span class="keyword">else</span> <span class="keyword">if</span>(xhr.readyState == <span class="number">4</span>){</div><div class="line">            <span class="comment">/*error*/</span></div><div class="line">            options.error &amp;&amp; options.error(<span class="string">&apos;you request fail !&apos;</span>);</div><div class="line">        }</div><div class="line">    }</div><div class="line">}</div><div class="line">$.post = <span class="function"><span class="keyword">function</span>(<span class="params">options</span>)</span>{</div><div class="line">    options.type = <span class="string">&apos;post&apos;</span>;</div><div class="line">    $.ajax(options);</div><div class="line">}</div><div class="line">$.get = <span class="function"><span class="keyword">function</span>(<span class="params">options</span>)</span>{</div><div class="line">    options.type = <span class="string">&apos;get&apos;</span>;</div><div class="line">    $.ajax(options);</div><div class="line">}</div></pre></td></tr></table></figure>
<h2 id="jQuery&#x7684;ajax"><a href="#jQuery&#x7684;ajax" class="headerlink" title="jQuery&#x7684;ajax"></a>jQuery&#x7684;ajax</h2><p>jQuery&#x4E3A;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x4E86;&#x66F4;&#x5F3A;&#x5927;&#x7684;Ajax&#x5C01;&#x88C5;</p>
<ul>
<li><code>$.ajax({})</code> <ul>
<li>&#x53EF;&#x914D;&#x7F6E;&#x65B9;&#x5F0F;&#x53D1;&#x8D77;Ajax&#x8BF7;&#x6C42;</li>
</ul>
</li>
<li><code>$.get()</code> <ul>
<li>&#x4EE5;GET&#x65B9;&#x5F0F;&#x53D1;&#x8D77;Ajax&#x8BF7;&#x6C42;</li>
</ul>
</li>
<li><code>$.post()</code> <ul>
<li>&#x4EE5;POST&#x65B9;&#x5F0F;&#x53D1;&#x8D77;Ajax&#x8BF7;&#x6C42;</li>
</ul>
</li>
<li><code>$(&apos;form&apos;).serialize()</code> <ul>
<li>&#x5E8F;&#x5217;&#x5316;&#x8868;&#x5355;&#xFF08;&#x5373;&#x683C;&#x5F0F;&#x5316;key=val&amp;key=val&#xFF09;</li>
</ul>
</li>
<li><code>url</code> <ul>
<li>&#x63A5;&#x53E3;&#x5730;&#x5740;</li>
</ul>
</li>
<li><code>type</code> <ul>
<li>&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;</li>
</ul>
</li>
<li><code>timeout</code> <ul>
<li>&#x8BF7;&#x6C42;&#x8D85;&#x65F6;</li>
</ul>
</li>
<li><code>dataType</code> <ul>
<li>&#x670D;&#x52A1;&#x5668;&#x8FD4;&#x56DE;&#x683C;&#x5F0F;</li>
</ul>
</li>
<li><code>contentType</code><ul>
<li>&#x6307;&#x5B9A;&#x8BF7;&#x6C42;&#x7684; HTTP Content-Type</li>
</ul>
</li>
<li><code>data</code> <ul>
<li>&#x53D1;&#x9001;&#x8BF7;&#x6C42;&#x6570;&#x636E;</li>
</ul>
</li>
<li><code>beforeSend: function () {}</code> <ul>
<li>&#x8BF7;&#x6C42;&#x53D1;&#x8D77;&#x524D;&#x8C03;&#x7528;</li>
</ul>
</li>
<li><code>success</code> <ul>
<li>&#x6210;&#x529F;&#x54CD;&#x5E94;&#x540E;&#x8C03;&#x7528;</li>
</ul>
</li>
<li><code>error</code> <ul>
<li>&#x9519;&#x8BEF;&#x54CD;&#x5E94;&#x65F6;&#x8C03;&#x7528;</li>
</ul>
</li>
<li><code>complete</code> <ul>
<li>&#x54CD;&#x5E94;&#x5B8C;&#x6210;&#x65F6;&#x8C03;&#x7528;&#xFF08;&#x5305;&#x62EC;&#x6210;&#x529F;&#x548C;&#x5931;&#x8D25;&#xFF09;</li>
</ul>
</li>
<li><code>timeout</code><ul>
<li>&#x8D85;&#x65F6;&#x65F6;&#x95F4;</li>
</ul>
</li>
<li><code>cache</code><ul>
<li>&#x5BF9;&#x4E8E; GET &#x8BF7;&#x6C42;</li>
</ul>
</li>
<li><code>ifModified</code><ul>
<li>&#x5F53;&#x4E3A; true &#x65F6;&#xFF0C;jQuery &#x4F1A;&#x4E3A;&#x8BF7;&#x6C42;&#x7684;&#x6BCF;&#x4E00;&#x4E2A; URL &#x8BB0;&#x5F55; Last-Modified &#x548C; If-None-Match &#x54CD;&#x5E94;&#x5934;&#x7684;&#x503C;</li>
</ul>
</li>
<li><code>global</code><ul>
<li>&#x662F;&#x5426;&#x89E6;&#x53D1;&#x4E0A;&#x9762;&#x63CF;&#x8FF0;&#x7684; Ajax &#x8BF7;&#x6C42;&#x8FC7;&#x7A0B;&#x4E2D;&#x7684;&#x4E8B;&#x4EF6;</li>
</ul>
</li>
</ul>
<p><a href="http://www.w3school.com.cn/jquery/jquery_ref_ajax.asp" target="_blank" rel="external">jQuery Ajax&#x4ECB;&#x7ECD;</a> </p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        
  <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
    <div>感谢您的支持！</div>
    <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
      <span>打 赏</span>
    </button>
    <div id="QR" style="display: none;">
      
        <div id="wechat" style="display: inline-block">
          <img id="wechat_qr" src="http://ofy7k3v4s.bkt.clouddn.com/wcpayCode.jpg" alt="Hongqin Ma WeChat Pay"/>
          <p>微信打赏</p>
        </div>
      
      
        <div id="alipay" style="display: inline-block">
          <img id="alipay_qr" src="http://ofy7k3v4s.bkt.clouddn.com/apayCode.jpg" alt="Hongqin Ma Alipay"/>
          <p>支付宝打赏</p>
        </div>
      
    </div>
  </div>


      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Ajax/" rel="tag">#Ajax</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2014/12/17/22-JSON/" rel="next" title="JSON 数据">
                <i class="fa fa-chevron-left"></i> JSON 数据
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2015/01/20/Built-Hexo-Blog/" rel="prev" title="Hexo博客搭建">
                Hexo博客搭建 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        <div class="ds-share flat" data-thread-key="2015/01/15/23-Ajax/"
     data-title="Ajax"
     data-content=""
     data-url="https://hongqinma.github.io/2015/01/15/23-Ajax/">
  <div class="ds-share-inline">
    <ul  class="ds-share-icons-16">

      <li data-toggle="ds-share-icons-more"><a class="ds-more" href="javascript:void(0);">分享到：</a></li>
      <li><a class="ds-weibo" href="javascript:void(0);" data-service="weibo">微博</a></li>
      <li><a class="ds-qzone" href="javascript:void(0);" data-service="qzone">QQ空间</a></li>
      <li><a class="ds-qqt" href="javascript:void(0);" data-service="qqt">腾讯微博</a></li>
      <li><a class="ds-wechat" href="javascript:void(0);" data-service="wechat">微信</a></li>

    </ul>
    <div class="ds-share-icons-more">
    </div>
  </div>
</div>
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2015/01/15/23-Ajax/"
           data-title="Ajax" data-url="https://hongqinma.github.io/2015/01/15/23-Ajax/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            Overview
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="//schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/photo.jpg"
               alt="Hongqin Ma" />
          <p class="site-author-name" itemprop="name">Hongqin Ma</p>
          <p class="site-description motion-element" itemprop="description">Spell at all costs， to rush you in the future. </p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">68</span>
              <span class="site-state-item-name">posts</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">16</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">57</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/HongqinMa" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://twitter.com/HongqinMa" target="_blank" title="Twitter">
                  
                    <i class="fa fa-fw fa-twitter"></i>
                  
                  Twitter
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://www.facebook.com/profile.php?id=100006581058735" target="_blank" title="Facebook">
                  
                    <i class="fa fa-fw fa-facebook"></i>
                  
                  Facebook
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://www.zhihu.com/people/HirakuMa" target="_blank" title="知乎">
                  
                    <i class="fa fa-fw fa-share-alt"></i>
                  
                  知乎
                </a>
              </span>
            
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              Links
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/rubylouvre/" title="司徒正美" target="_blank">司徒正美</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/sanshi/" title="三生石上" target="_blank">三生石上</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.cnblogs.com/TomXu/" title="汤姆大叔" target="_blank">汤姆大叔</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://gold.xitu.io/" title="掘金" target="_blank">掘金</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://segmentfault.com/" title="segmentfault" target="_blank">segmentfault</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://www.jianshu.com/users/1cbb94e5ed4d/latest_articles" title="简书" target="_blank">简书</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://home.cnblogs.com/" title="博客园" target="_blank">博客园</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="https://www.awesomes.cn/" title="Awesomes" target="_blank">Awesomes</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#服务器、网络基础、相关知识介绍"><span class="nav-number">1.</span> <span class="nav-text">服务器、网络基础、相关知识介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#服务器介绍："><span class="nav-number">1.1.</span> <span class="nav-text">服务器介绍：</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#常见的服务器软件有："><span class="nav-number">1.1.1.</span> <span class="nav-text">常见的服务器软件有：</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#网络基础："><span class="nav-number">2.</span> <span class="nav-text">网络基础：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#IP地址"><span class="nav-number">2.1.</span> <span class="nav-text">IP地址</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#域名"><span class="nav-number">2.2.</span> <span class="nav-text">域名</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#DNS服务"><span class="nav-number">2.3.</span> <span class="nav-text">DNS服务</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#端口"><span class="nav-number">2.4.</span> <span class="nav-text">端口</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#软件架构"><span class="nav-number">3.</span> <span class="nav-text">软件架构</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#C-S结构"><span class="nav-number">3.1.</span> <span class="nav-text">C/S结构</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#B-S结构"><span class="nav-number">3.2.</span> <span class="nav-text">B/S结构</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#网络传输协议"><span class="nav-number">4.</span> <span class="nav-text">网络传输协议</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#常见协议"><span class="nav-number">4.1.</span> <span class="nav-text">常见协议</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#http协议"><span class="nav-number">4.2.</span> <span class="nav-text">http协议</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#请求由-4-部分组成"><span class="nav-number">4.2.1.</span> <span class="nav-text">请求由 4 部分组成</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#响应和响应报文"><span class="nav-number">4.3.</span> <span class="nav-text">响应和响应报文</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JavaScript-原生的-Ajax"><span class="nav-number">5.</span> <span class="nav-text">JavaScript 原生的 Ajax</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#异步"><span class="nav-number">5.1.</span> <span class="nav-text">异步</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#XMLHttpRequest-对象"><span class="nav-number">5.2.</span> <span class="nav-text">XMLHttpRequest 对象</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#XMLHttpRequest-对象使用"><span class="nav-number">5.3.</span> <span class="nav-text">XMLHttpRequest 对象使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#GET-请求"><span class="nav-number">5.4.</span> <span class="nav-text">GET 请求</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#POST-请求"><span class="nav-number">5.5.</span> <span class="nav-text">POST 请求</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#关于表单序列化"><span class="nav-number">5.6.</span> <span class="nav-text">关于表单序列化</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#超时设定"><span class="nav-number">5.7.</span> <span class="nav-text">超时设定</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#进度事件"><span class="nav-number">5.8.</span> <span class="nav-text">进度事件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#API-总结"><span class="nav-number">5.9.</span> <span class="nav-text">API 总结</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#封装ajax工具函数"><span class="nav-number">5.10.</span> <span class="nav-text">封装ajax工具函数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery的ajax"><span class="nav-number">6.</span> <span class="nav-text">jQuery的ajax</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Hongqin Ma</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>

<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_site_pv">
    &nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;Page Views: <span id="busuanzi_value_site_pv"></span> 
</span>

        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv"><i class="fa fa-user"></i><span class="busuanzi-value" id="busuanzi_value_site_uv"></span></span>
  

  
    <span class="site-pv"><i class="fa fa-eye"></i><span class="busuanzi-value" id="busuanzi_value_site_pv"></span></span>
  
  
</div>



        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.2"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.2"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.2"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"Hiraku"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  






  
  

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  
  
  <!-- custom analytics part create by xiamo -->
<script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
<script>AV.initialize("PPmoIQxeu8Sd21h6Tl9TthNx-gzGzoHsz", "rTvbY2H7DvWzRipiBwn72RQ4");</script>
<script>
function showTime(Counter) {
  var query = new AV.Query(Counter);
  $(".leancloud_visitors").each(function() {
    var url = $(this).attr("id").trim();
    query.equalTo("url", url);
    query.find({
      success: function(results) {
        if (results.length == 0) {
          var content = '0 ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
          return;
        }
        for (var i = 0; i < results.length; i++) {
          var object = results[i];
          var content = object.get('time') + ' ' + $(document.getElementById(url)).text();
          $(document.getElementById(url)).text(content);
        }
      },
      error: function(object, error) {
        console.log("Error: " + error.code + " " + error.message);
      }
    });

  });
}

function addCount(Counter) {
  var Counter = AV.Object.extend("Counter");
  url = $(".leancloud_visitors").attr('id').trim();
  title = $(".leancloud_visitors").attr('data-flag-title').trim();
  var query = new AV.Query(Counter);
  query.equalTo("url", url);
  query.find({
    success: function(results) {
      if (results.length > 0) {
        var counter = results[0];
        counter.fetchWhenSave(true);
        counter.increment("time");
        counter.save(null, {
          success: function(counter) {
            var content =  counter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(counter, error) {
            console.log('Failed to save Visitor num, with error message: ' + error.message);
          }
        });
      } else {
        var newcounter = new Counter();
        newcounter.set("title", title);
        newcounter.set("url", url);
        newcounter.set("time", 1);
        newcounter.save(null, {
          success: function(newcounter) {
              console.log("newcounter.get('time')="+newcounter.get('time'));
            var content = newcounter.get('time') + ' ' + $(document.getElementById(url)).text();
            $(document.getElementById(url)).text(content);
          },
          error: function(newcounter, error) {
            console.log('Failed to create');
          }
        });
      }
    },
    error: function(error) {
      console.log('Error:' + error.code + " " + error.message);
    }
  });
}
$(function() {
  var Counter = AV.Object.extend("Counter");
  if ($('.leancloud_visitors').length == 1) {
    addCount(Counter);
  } else if ($('.post-title-link').length > 1) {
    showTime(Counter);
  }
}); 
</script>

  
</body>
</html>
